text:
#include <stdio.h>
#include <stddef.h>
#include <logging/log_backend.h>
#include <logging/log_backend_std.h>
#include <logging/log_core.h>
#include <logging/log_msg.h>
#include <logging/log_output.h>
#include <irq.h>
#include <arch/posix/posix_trace.h>

#define _STDOUT_BUF_SIZE 256
static char stdout_buff[_STDOUT_BUF_SIZE];
static int n_pend; /* Number of pending characters in buffer */

static void preprint_char(int c)
{
	int printnow = 0;

	if (c == '\r') {
		/* Discard carriage returns */
		return;
	}
	if (c != '\n') {
		stdout_buff[n_pend++] = c;
		stdout_buff[n_pend] = 0;
	} else {
		printnow = 1;
	}

	if (n_pend >= _STDOUT_BUF_SIZE - 1) {
		printnow = 1;
	}

	if (printnow) {
		posix_print_trace("%s\n", stdout_buff);
		n_pend = 0;
		stdout_buff[0] = 0;
	}
}

static uint8_t buf[_STDOUT_BUF_SIZE];

static int char_out(uint8_t *data, size_t length, void *ctx)
{
	for (size_t i = 0; i < length; i++) {
		preprint_char(data[i]);
	}

	return length;
}

LOG_OUTPUT_DEFINE(log_output_posix, char_out, buf, sizeof(buf));

static void put(const struct log_backend *const backend,
		struct log_msg *msg)
{
	log_msg_get(msg);

	uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;

	if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
		if (posix_trace_over_tty(0)) {
			flags |= LOG_OUTPUT_FLAG_COLORS;
		}
	}

	if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
		flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
	}

	log_output_msg_process(&log_output_posix, msg, flags);

	log_msg_put(msg);

}

static void panic(struct log_backend const *const backend)
{
	log_output_flush(&log_output_posix);
}

static void dropped(const struct log_backend *const backend, uint32_t cnt)
{
	ARG_UNUSED(backend);

	log_output_dropped_process(&log_output_posix, cnt);
}

static void sync_string(const struct log_backend *const backend,
		     struct log_msg_ids src_level, uint32_t timestamp,
		     const char *fmt, va_list ap)
{
	uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
	uint32_t key;

	if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
		flags |= LOG_OUTPUT_FLAG_COLORS;
	}

	if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
		flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
	}

	key = irq_lock();
	log_output_string(&log_output_posix, src_level,
			  timestamp, fmt, ap, flags);
	irq_unlock(key);
}

static void sync_hexdump(const struct log_backend *const backend,
			 struct log_msg_ids src_level, uint32_t timestamp,
			 const char *metadata, const uint8_t *data, uint32_t length)
{
	uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
	uint32_t key;

	if (IS_ENABLED(CONFIG_LOG_BACKEND_SHOW_COLOR)) {
		flags |= LOG_OUTPUT_FLAG_COLORS;
	}

	if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
		flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
	}

	key = irq_lock();
	log_output_hexdump(&log_output_posix, src_level, timestamp,
			metadata, data, length, flags);
	irq_unlock(key);
}

static void process(const struct log_backend *const backend,
		union log_msg2_generic *msg)
{
	uint32_t flags = log_backend_std_get_flags();

	log_output_msg2_process(&log_output_posix, &msg->log, flags);
}

const struct log_backend_api log_backend_native_posix_api = {
	.process = IS_ENABLED(CONFIG_LOG2) ? process : NULL,
	.put = IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) ? put : NULL,
	.put_sync_string = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ?
			sync_string : NULL,
	.put_sync_hexdump = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ?
			sync_hexdump : NULL,
	.panic = panic,
	.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
};

LOG_BACKEND_DEFINE(log_backend_native_posix,
		   log_backend_native_posix_api,
		   true);


text:
<?php

namespace CachetHQ\Cachet\Services\Modules;

/**
 * This is the module manager class.
 *
 * @author Connor S. Parks <connor@connorvg.tv>
 */
class Manager
{
    /**
     * Groups the modules.
     *
     * @param array $modules
     * @param array $groups
     *
     * @return array
     */
    public function groupModules(array $modules, array $groups = [])
    {
        $grouped = [];
        $length = count($modules);
        foreach ($modules as $order => $module) {
            if (!is_array($module) || empty($module['group'])) {
                $order = array_get($module, 'order', PHP_INT_MAX - $length + $order);

                $grouped[] = [$module, 'order' => $order];

                continue;
            }

            $group = $module['group'];
            if (empty($grouped[$group])) {
                $grouped[$group] = [$module];

                continue;
            }

            $grouped[$group][] = $module;
        }

        foreach ($groups as $group => $order) {
            if (empty($grouped[$group])) {
                continue;
            }

            $grouped[$group]['order'] = $order;
        }

        return $grouped;
    }

    /**
     * Orders the modules.
     *
     * @param array $modules
     *
     * @return array
     */
    public function orderModules($modules)
    {
        $modules = array_numeric_sort($modules);

        foreach ($modules as $group => $subModules) {
            $modules[$group] = array_numeric_sort($subModules);
        }

        return $modules;
    }
}

redpajama_set_name: RedPajamaGithub


text:
package com.xin.bladedb.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.xin.bladedb.MainActivity;
import com.xin.bladedb.MainApplication;
import com.xin.bladedb.R;
import com.xin.bladedb.signup.SignUpActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;

public class LoginActivity extends AppCompatActivity implements LoginView {

    @BindView(R.id.input_email)
    EditText emailField;

    @BindView(R.id.input_password)
    EditText passwordField;

    @BindView(R.id.login)
    Button loginButton;

    @BindView(R.id.sign_up)
    Button signUpButton;

    @BindView(R.id.login_progress_bar)
    ProgressBar progressBar;

    @BindView(R.id.login_container)
    LinearLayout loginContainer;

    @Inject
    LoginPresenter loginPresenter;

    @Inject
    FirebaseAuth firebaseAuth;

    FirebaseAuth.AuthStateListener firebaseListener;

    //Android lifecycle calls
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        passwordField.setTransformationMethod(new PasswordTransformationMethod());
        ((MainApplication) getApplication()).getFireBaseComponent().inject(this);
        loginPresenter.setView(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        firebaseListener =  new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    Timber.d("User is signed in.");
                    continueToMainActivity();
                } else {
                    // User is signed out
                    Timber.d("User is signed out.");
                }
            }
        };
        firebaseAuth.addAuthStateListener(firebaseListener);
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (firebaseListener != null) {
            firebaseAuth.removeAuthStateListener(firebaseListener);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Timber.d("Activity Result.");
        switch (requestCode) {
            case SignUpActivity.SIGN_UP:
                Timber.d("Passing data through");
                if (resultCode == RESULT_OK) {
                    emailField.setText(data.getStringExtra("email"));
                    passwordField.setText(data.getStringExtra("password"));
                }
                break;
            default:
                break;
        }
    }

    //Login View
    @Override
    public void hideProgress() {
        loginContainer.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void showProgress() {
        loginContainer.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void showToast(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void continueToMainActivity() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void showEmailWarning(String message) {
        emailField.setError(message);
    }

    @Override
    public void showPasswordWarning(String message) {
        passwordField.setError(message);
    }

    // OnClickListeners
    @OnClick(R.id.login)
    public void login() {
        loginPresenter.login(emailField.getText().toString(), passwordField.getText().toString());
    }

    @OnClick(R.id.sign_up)
    public void signUp() {
        Intent intent = new Intent(this, SignUpActivity.class);
        startActivityForResult(intent, SignUpActivity.SIGN_UP);
    }

}


text:
package com.deeal.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.deeal.callback.FansListCallback;
import com.deeal.model.mycenter.MyFansInfo;
import com.deeal.tools.URL;
import com.deeal.tools.mycenter.MyFansManager;
import com.deeal.view.RoundImageView;
import com.example.deeal.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class FansListActivity extends Activity {
	//定义FansItemHolder需要的一些东西
	private FansItemHolder holder;
	// 粉丝头像  粉丝id  粉丝个性签名
	private RoundImageView img_fans_user_head;
	private TextView tv_fansid,tv_fans_personalwords;
	private View itemView;
	private PullToRefreshListView lvFans;
	private LinkedList<HashMap<String, Object>> data = new LinkedList<HashMap<String, Object>>();

	@ViewInject(R.id.btn_fanslist_return)
	private ImageButton imagebtn_fanslist_returnButton;

	@OnClick(R.id.btn_fanslist_return)
	public void imagebtn_fanslist_returnButton(View v) {
		finish();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fanslist);

		initItems();

	}

	public void initItems(){

		this.lvFans = (PullToRefreshListView) findViewById(R.id.lv_fans);

		itemView=LayoutInflater.from(this).inflate(R.layout.fans_list_item, null);
		img_fans_user_head=(RoundImageView) itemView.findViewById(R.id.img_fans_user_head);
		tv_fansid=(TextView) itemView.findViewById(R.id.tv_fansid);
		tv_fans_personalwords=(TextView) itemView.findViewById(R.id.tv_fans_personalwords);
		holder=new FansItemHolder(img_fans_user_head, tv_fansid, tv_fans_personalwords);

		this.lvFans.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				startFriendCenterActivity();
			}
		});

		// 设定下拉监听函数
		this.lvFans.setOnRefreshListener(new OnRefreshListener<ListView>() {
			@Override
			public void onRefresh(PullToRefreshBase<ListView> refreshView) {
				String label = DateUtils.formatDateTime(
						getApplicationContext(), System.currentTimeMillis(),
						DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE
								| DateUtils.FORMAT_ABBREV_ALL);
				refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
				//lvFans.onRefreshComplete();
				new GetDataTask().execute();
			}
		});

		getData();
	}

	private void getData() {
		FansListCallback callback=new FansListCallback(this, holder, data, lvFans);
		HttpUtils httpUtils=new HttpUtils();
		httpUtils.send(HttpMethod.GET, URL.URL_GetFansList, callback);
	}

	public void startFriendCenterActivity() {
		Intent i = new Intent();
		i.setClass(this, FriendCenterActivity.class);
		startActivity(i);
	}

	private class GetDataTask extends
			AsyncTask<Void, Void, HashMap<String, Object>> {

		// 后台处理部分
		@Override
		protected HashMap<String, Object> doInBackground(Void... params) {
			// Simulates a background job.
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
			HashMap<String, Object> map = new HashMap<String, Object>();
			try {
				map = new HashMap<String, Object>();
				map.put("id", "anthow");
				map.put("personalwords", "222222");
			} catch (Exception e) {
				// TODO: handle exception
				setTitle("map出错了");
				return null;
			}
			return map;
		}

		// 这里是对刷新的响应,可以利用addFirst()和addLast()函数将新加的内容加到LISTView中
		// 根据AsyncTask的原理,onPostExecute里的result的值就是doInBackground()的返回值
		@Override
		protected void onPostExecute(HashMap<String, Object> result) {
			// 在头部增加新添内容

			try {
				//data.addFirst(result);

				// 通知程序数据集已经改变,如果不做通知,那么将不会刷新mListItems的集合
				//adapter.notifyDataSetChanged();
				lvFans.onRefreshComplete();
			} catch (Exception e) {
				// TODO: handle exception
				setTitle(e.getMessage());
			}
			super.onPostExecute(result);
		}

	}

	public class FansItemHolder {
		public FansItemHolder(RoundImageView img_fans_user_head,
				TextView tv_fansid, TextView tv_fans_personalwords) {
			this.img_fans_user_head=img_fans_user_head;
			this.tv_fansid=tv_fansid;
			this.tv_fans_personalwords=tv_fans_personalwords;
		}
		/* @ViewInject(R.id.img_fans_user_head) */
		public RoundImageView img_fans_user_head;

		/* @ViewInject(R.id.tv_fansid) */
		public TextView tv_fansid;

		/* @ViewInject(R.id.tv_fans_personalwords) */
		public TextView tv_fans_personalwords;
	}
}


text:
using System;
using SmugMug.v2.Authentication;

namespace SmugMug.v2.Types
{
    public partial class CatalogSkuEntity : SmugMugEntity
    {
        private float _borderHeight;
        private float _borderWidth;
        private long _cartItemLimit;
        private bool _enabled;
        private long _maxQuantity;
        private long _minResHeight;
        private long _minResWidth;
        private bool _priceable;
        private long _skuID;

        public float BorderHeight {
            get {
                return _borderHeight;
            }
            set {
                if (_borderHeight != value)
                {
                    NotifyPropertyValueChanged("BorderHeight", oldValue:_borderHeight, newValue: value);
                    _borderHeight = value;
                }
            }
        }

        public float BorderWidth {
            get {
                return _borderWidth;
            }
            set {
                if (_borderWidth != value)
                {
                    NotifyPropertyValueChanged("BorderWidth", oldValue:_borderWidth, newValue: value);
                    _borderWidth = value;
                }
            }
        }

        public long CartItemLimit {
            get {
                return _cartItemLimit;
            }
            set {
                if (_cartItemLimit != value)
                {
                    NotifyPropertyValueChanged("CartItemLimit", oldValue:_cartItemLimit, newValue: value);
                    _cartItemLimit = value;
                }
            }
        }

        public bool Enabled {
            get {
                return _enabled;
            }
            set {
                if (_enabled != value)
                {
                    NotifyPropertyValueChanged("Enabled", oldValue:_enabled, newValue: value);
                    _enabled = value;
                }
            }
        }

        public long MaxQuantity {
            get {
                return _maxQuantity;
            }
            set {
                if (_maxQuantity != value)
                {
                    NotifyPropertyValueChanged("MaxQuantity", oldValue:_maxQuantity, newValue: value);
                    _maxQuantity = value;
                }
            }
        }

        public long MinResHeight {
            get {
                return _minResHeight;
            }
            set {
                if (_minResHeight != value)
                {
                    NotifyPropertyValueChanged("MinResHeight", oldValue:_minResHeight, newValue: value);
                    _minResHeight = value;
                }
            }
        }

        public long MinResWidth {
            get {
                return _minResWidth;
            }
            set {
                if (_minResWidth != value)
                {
                    NotifyPropertyValueChanged("MinResWidth", oldValue:_minResWidth, newValue: value);
                    _minResWidth = value;
                }
            }
        }

        public bool Priceable {
            get {
                return _priceable;
            }
            set {
                if (_priceable != value)
                {
                    NotifyPropertyValueChanged("Priceable", oldValue:_priceable, newValue: value);
                    _priceable = value;
                }
            }
        }

        public long SkuID {
            get {
                return _skuID;
            }
            set {
                if (_skuID != value)
                {
                    NotifyPropertyValueChanged("SkuID", oldValue:_skuID, newValue: value);
                    _skuID = value;
                }
            }
        }
    }
}


text:
/*
 * drivers/i2c/chips/ds1374.c
 *
 * I2C client/driver for the Maxim/Dallas DS1374 Real-Time Clock
 *
 * Author: Randy Vinson <rvinson@mvista.com>
 *
 * Based on the m41t00.c by Mark Greer <mgreer@mvista.com>
 *
 * 2005 (c) MontaVista Software, Inc. This file is licensed under
 * the terms of the GNU General Public License version 2. This program
 * is licensed "as is" without any warranty of any kind, whether express
 * or implied.
 */
/*
 * This i2c client/driver wedges between the drivers/char/genrtc.c RTC
 * interface and the SMBus interface of the i2c subsystem.
 * It would be more efficient to use i2c msgs/i2c_transfer directly but, as
 * recommened in .../Documentation/i2c/writing-clients section
 * "Sending and receiving", using SMBus level communication is preferred.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/rtc.h>
#include <linux/bcd.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>

#define DS1374_REG_TOD0		0x00
#define DS1374_REG_TOD1		0x01
#define DS1374_REG_TOD2		0x02
#define DS1374_REG_TOD3		0x03
#define DS1374_REG_WDALM0	0x04
#define DS1374_REG_WDALM1	0x05
#define DS1374_REG_WDALM2	0x06
#define DS1374_REG_CR		0x07
#define DS1374_REG_SR		0x08
#define DS1374_REG_SR_OSF	0x80
#define DS1374_REG_TCR		0x09

#define	DS1374_DRV_NAME		"ds1374"

static DEFINE_MUTEX(ds1374_mutex);

static struct i2c_driver ds1374_driver;
static struct i2c_client *save_client;

static unsigned short ignore[] = { I2C_CLIENT_END };
static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END };

static struct i2c_client_address_data addr_data = {
	.normal_i2c = normal_addr,
	.probe = ignore,
	.ignore = ignore,
};

static ulong ds1374_read_rtc(void)
{
	ulong time = 0;
	int reg = DS1374_REG_WDALM0;

	while (reg--) {
		s32 tmp;
		if ((tmp = i2c_smbus_read_byte_data(save_client, reg)) < 0) {
			dev_warn(&save_client->dev,
				 "can't read from rtc chip\n");
			return 0;
		}
		time = (time << 8) | (tmp & 0xff);
	}
	return time;
}

static void ds1374_write_rtc(ulong time)
{
	int reg;

	for (reg = DS1374_REG_TOD0; reg < DS1374_REG_WDALM0; reg++) {
		if (i2c_smbus_write_byte_data(save_client, reg, time & 0xff)
		    < 0) {
			dev_warn(&save_client->dev,
				 "can't write to rtc chip\n");
			break;
		}
		time = time >> 8;
	}
}

static void ds1374_check_rtc_status(void)
{
	s32 tmp;

	tmp = i2c_smbus_read_byte_data(save_client, DS1374_REG_SR);
	if (tmp < 0) {
		dev_warn(&save_client->dev,
			 "can't read status from rtc chip\n");
		return;
	}
	if (tmp & DS1374_REG_SR_OSF) {
		dev_warn(&save_client->dev,
			 "oscillator discontinuity flagged, time unreliable\n");
		tmp &= ~DS1374_REG_SR_OSF;
		tmp = i2c_smbus_write_byte_data(save_client, DS1374_REG_SR,
						tmp & 0xff);
		if (tmp < 0)
			dev_warn(&save_client->dev,
				 "can't clear discontinuity notification\n");
	}
}

ulong ds1374_get_rtc_time(void)
{
	ulong t1, t2;
	int limit = 10;		/* arbitrary retry limit */

	mutex_lock(&ds1374_mutex);

	/*
	 * Since the reads are being performed one byte at a time using
	 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
	 * carry will occur during the read. To detect this, 2 reads are
	 * performed and compared.
	 */
	do {
		t1 = ds1374_read_rtc();
		t2 = ds1374_read_rtc();
	} while (t1 != t2 && limit--);

	mutex_unlock(&ds1374_mutex);

	if (t1 != t2) {
		dev_warn(&save_client->dev,
			 "can't get consistent time from rtc chip\n");
		t1 = 0;
	}

	return t1;
}

static ulong new_time;

static void ds1374_set_work(struct work_struct *work)
{
	ulong t1, t2;
	int limit = 10;		/* arbitrary retry limit */

	t1 = new_time;

	mutex_lock(&ds1374_mutex);

	/*
	 * Since the writes are being performed one byte at a time using
	 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
	 * carry will occur during the write. To detect this, the write
	 * value is read back and compared.
	 */
	do {
		ds1374_write_rtc(t1);
		t2 = ds1374_read_rtc();
	} while (t1 != t2 && limit--);

	mutex_unlock(&ds1374_mutex);

	if (t1 != t2)
		dev_warn(&save_client->dev,
			 "can't confirm time set from rtc chip\n");
}

static struct workqueue_struct *ds1374_workqueue;

static DECLARE_WORK(ds1374_work, ds1374_set_work);

int ds1374_set_rtc_time(ulong nowtime)
{
	new_time = nowtime;

	if (in_interrupt())
		queue_work(ds1374_workqueue, &ds1374_work);
	else
		ds1374_set_work(NULL);

	return 0;
}

/*
 *****************************************************************************
 *
 *	Driver Interface
 *
 *****************************************************************************
 */
static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
{
	struct i2c_client *client;
	int rc;

	client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
	if (!client)
		return -ENOMEM;

	strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
	client->addr = addr;
	client->adapter = adap;
	client->driver = &ds1374_driver;

	ds1374_workqueue = create_singlethread_workqueue("ds1374");
	if (!ds1374_workqueue) {
		kfree(client);
		return -ENOMEM;	/* most expected reason */
	}

	if ((rc = i2c_attach_client(client)) != 0) {
		kfree(client);
		return rc;
	}

	save_client = client;

	ds1374_check_rtc_status();

	return 0;
}

static int ds1374_attach(struct i2c_adapter *adap)
{
	return i2c_probe(adap, &addr_data, ds1374_probe);
}

static int ds1374_detach(struct i2c_client *client)
{
	int rc;

	if ((rc = i2c_detach_client(client)) == 0) {
		kfree(i2c_get_clientdata(client));
		destroy_workqueue(ds1374_workqueue);
	}
	return rc;
}

static struct i2c_driver ds1374_driver = {
	.driver = {
		.name	= DS1374_DRV_NAME,
	},
	.id = I2C_DRIVERID_DS1374,
	.attach_adapter = ds1374_attach,
	.detach_client = ds1374_detach,
};

static int __init ds1374_init(void)
{
	return i2c_add_driver(&ds1374_driver);
}

static void __exit ds1374_exit(void)
{
	i2c_del_driver(&ds1374_driver);
}

module_init(ds1374_init);
module_exit(ds1374_exit);

MODULE_AUTHOR("Randy Vinson <rvinson@mvista.com>");
MODULE_DESCRIPTION("Maxim/Dallas DS1374 RTC I2C Client Driver");
MODULE_LICENSE("GPL");


text:
using System;
using System.ComponentModel.Composition;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using ProductManager.Web.Service;
using System.Collections.ObjectModel;
using ProductManager.ViewData.Entity;
using System.Collections.Generic;
using ProductManager.Controls;
using ProductManager.Views.PlanManager;
using System.IO;
using Lite.ExcelLibrary.SpreadSheet;
using ProductManager.Web.Model;
using System.Linq;
using Microsoft.Windows.Data.DomainServices;
using System.ComponentModel;
using ProductManager.FileUploader;

namespace ProductManager.ViewModel.PlanManager
{
    [Export("PlanEdit")]
    public class PlanEditViewModel : NotifyPropertyChanged
    {
        private PlanManagerDomainContext planManagerDomainContext = new PlanManagerDomainContext();
        private ProductDomainContext ProductDomainContext = new ProductDomainContext();

        public ObservableCollection<ProjectEntity> ProjectList { get; set; }

        private DomainCollectionView<project> projectView;
        private DomainCollectionViewLoader<project> projectLoader;
        private EntityList<project> prjectSource;

        private DomainCollectionView<plan> planView;
        private DomainCollectionViewLoader<plan> planLoader;
        private EntityList<plan> panSource;

        private Dictionary<string, int> departmentNameIdDictionary;
        private Dictionary<int, string> departmentIdNameDictionary;

        private Dictionary<string, UserProjectEntity> UserProjectEntityDictionary { get; set; }
        private ObservableCollection<string> importErrorList { get; set; }

        private bool isBusy = false;
        public bool IsBusy
        {
            get { return isBusy; }
            set
            {
                if (isBusy != value)
                {
                    isBusy = value;
                    UpdateChanged("IsBusy");
                }
            }
        }

        public ICollectionView CollectionProjectView
        {
            get { return this.projectView; }
        }

        private String filterContent;
        public String FilterContent
        {
            get
            {
                return filterContent;
            }
            set
            {
                if (filterContent != value)
                {
                    filterContent = value;
                    UpdateChanged("FilterContent");
                }
            }
        }

        private bool isFilter;
        public bool IsFilter
        {
            get
            {
                return isFilter;
            }
            set
            {
                if (isFilter != value)
                {
                    isFilter = value;
                    UpdateChanged("IsFilter");
                }
            }
        }

        public ObservableCollection<String> FilterList { get; set; }

        private String selectFilerList;
        public String SelectFilerList
        {
            get
            {
                return selectFilerList;
            }
            set
            {
                if (selectFilerList != value)
                {
                    selectFilerList = value;
                    UpdateChanged("SelectFilerList");
                }
            }
        }

        private bool isUserProject;
        public bool IsUserProject
        {
            get
            {
                return isUserProject;
            }
            set
            {
                if (isUserProject != value)
                {
                    isUserProject = value;
                    UpdateChanged("IsUserProject");
                }
            }
        }

        public void LoadData()
        {
            IsBusy = true;
            ProductDomainContext.user_projects.Clear();
            planManagerDomainContext.plans.Clear();

            this.panSource = new EntityList<plan>(this.planManagerDomainContext.plans);
            this.planLoader = new DomainCollectionViewLoader<plan>(
                this.LoadPlanEntities,
                this.LoadOperationPlanCompleted);
            this.planView = new DomainCollectionView<plan>(this.planLoader, this.panSource);

            App app = Application.Current as App;
            LoadOperation<user_project> loadOperationUserProject =
               ProductDomainContext.Load<user_project>(ProductDomainContext.GetUserProjectQuery(app.UserInfo.UserID));
            loadOperationUserProject.Completed += LoadUserProjectComplete;
        }

        void LoadUserProjectComplete(object sender, EventArgs e)
        {
            UserProjectEntityDictionary.Clear();

            LoadOperation loadOperation = sender as LoadOperation;
            foreach (user_project user_project in loadOperation.Entities)
            {
                UserProjectEntity lUserProjectEntity = new UserProjectEntity();
                lUserProjectEntity.UserProject = user_project;
                lUserProjectEntity.Update();
                UserProjectEntityDictionary.Add(lUserProjectEntity.ManufactureNumber, lUserProjectEntity);
            }

            planManagerDomainContext.plan_extras.Clear();
            LoadOperation<plan_extra> loadOperationPlanExtra =
                planManagerDomainContext.Load<plan_extra>(planManagerDomainContext.GetPlan_extraQuery());
            loadOperationPlanExtra.Completed += loadOperationPlanExtra_Completed;
        }

        private LoadOperation<plan> LoadPlanEntities()
        {
            this.IsBusy = true;
            EntityQuery<plan> lQuery = this.planManagerDomainContext.GetPlanQuery();
            if (SelectProjectEntity != null)
            {
                lQuery = lQuery.Where(e => e.manufacture_number == SelectProjectEntity.ManufactureNumber);
            }
            return this.planManagerDomainContext.Load(lQuery.SortAndPageBy(this.planView));
        }

        private void LoadOperationPlanCompleted(LoadOperation<plan> aLoadOperation)
        {
            IsBusy = false;
        }

        void loadOperationPlan_Completed(object sender, EventArgs e)
        {

        }

        void loadOperationPlanExtra_Completed(object sender, EventArgs e)
        {
            planManagerDomainContext.departments.Clear();
            LoadOperation<department> loadOperationDepartment =
                planManagerDomainContext.Load<department>(planManagerDomainContext.GetDepartmentQuery());
            loadOperationDepartment.Completed += loadOperationDepartment_Completed;
        }

        void loadOperationDepartment_Completed(object sender, EventArgs e)
        {
            departmentNameIdDictionary.Clear();
            departmentIdNameDictionary.Clear();
            LoadOperation loadOperation = sender as LoadOperation;
            foreach (department department in loadOperation.Entities)
            {
                if (!departmentNameIdDictionary.Keys.Contains(department.department_name))
                {
                    departmentNameIdDictionary.Add(department.department_name, department.department_id);
                }
                departmentIdNameDictionary.Add(department.department_id, department.department_name);
            }

            planManagerDomainContext.projects.Clear();

            this.prjectSource = new EntityList<project>(this.planManagerDomainContext.projects);
            this.projectLoader = new DomainCollectionViewLoader<project>(
                this.LoadProjectEntities,
                this.LoadOperationProjectCompleted);
            this.projectView = new DomainCollectionView<project>(this.projectLoader, this.prjectSource);
            using (this.CollectionProjectView.DeferRefresh())
            {
                this.projectView.MoveToFirstPage();
            }
        }

        private LoadOperation<project> LoadProjectEntities()
        {
            if (!isFilter)
            {
                this.IsBusy = true;
                EntityQuery<project> lQuery = this.planManagerDomainContext.GetProjectQuery();
                return this.planManagerDomainContext.Load(lQuery.SortAndPageBy(this.projectView));
            }
            else
            {
                this.IsBusy = true;
                EntityQuery<project> lQuery = this.planManagerDomainContext.GetProjectQuery();
                if (selectFilerList == "生产令号")
                {
                    if (!String.IsNullOrEmpty(filterContent))
                    {
                        lQuery = lQuery.Where(e => e.manufacture_number.Contains(filterContent));
                    }
                }
                if (selectFilerList == "项目名称")
                {
                    if (!String.IsNullOrEmpty(filterContent))
                    {
                        lQuery = lQuery.Where(e => e.project_name.Contains(filterContent));
                    }
                }
                if (selectFilerList == "备注")
                {
                    if (!String.IsNullOrEmpty(filterContent))
                    {
                        lQuery = lQuery.Where(e => e.remark.Contains(filterContent));
                    }
                }
                if (selectFilerList == "年份")
                {
                    if (!String.IsNullOrEmpty(filterContent))
                    {
                        try
                        {
                            int year = Convert.ToInt32(filterContent);
                            lQuery = lQuery.Where(e => e.year_number == year);
                        }
                        catch (System.Exception ex)
                        {
                            NotifyWindow notifyWindow = new NotifyWindow("错误", "输入年份不合法");
                            notifyWindow.Show();
                        }

                    }
                }

                if (selectFilerList == "记录时间")
                {
                    if (!String.IsNullOrEmpty(filterContent))
                    {
                        try
                        {
                            DateTime remarkDate = Convert.ToDateTime(filterContent);
                            lQuery = lQuery.Where(e => e.record_date.Value.Year == remarkDate.Year && e.record_date.Value.Month == remarkDate.Month && e.record_date.Value.Day == remarkDate.Day);
                        }
                        catch (System.Exception ex)
                        {
                            NotifyWindow notifyWindow = new NotifyWindow("错误", "记录时间不合法 (YYYY-MM-DD)");
                            notifyWindow.Show();
                        }
                    }
                }
                return this.planManagerDomainContext.Load(lQuery.SortAndPageBy(this.projectView));
            }
        }

        private void LoadOperationProjectCompleted(LoadOperation<project> aLoadOperation)
        {
            ProjectList.Clear();
            foreach (project project in aLoadOperation.Entities)
            {
                ProjectEntity projectEntity = new ProjectEntity();
                projectEntity.Project = project;
                projectEntity.Update();

                if (!String.IsNullOrEmpty(projectEntity.PlanVersionID))
                {
                    IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras
                                                          where c.version_id == projectEntity.PlanVersionID
                                                            && c.manufacture_number == projectEntity.ManufactureNumber
                                                          select c;
                    if (0 != plan_extras.Count())
                    {
                        plan_extra planExtra = plan_extras.First<plan_extra>();
                        projectEntity.CompileUserName = planExtra.compile_user_name;
                        projectEntity.CompileDate = planExtra.compile_date;
                    }

                    IEnumerable<string> planVersions = from c in planManagerDomainContext.plans
                                                       where c.manufacture_number == projectEntity.ManufactureNumber
                                                       select c.version_id;
                    if (0 != planVersions.Count())
                    {
                        projectEntity.PlanVersionDictionary = new Dictionary<string, string>();
                        foreach (string item in planVersions)
                        {
                            if (projectEntity.PlanVersionDictionary.ContainsKey(item))
                            {
                                continue;
                            }
                            projectEntity.PlanVersionDictionary.Add(item, item);
                        }
                        projectEntity.HasHistory = true;
                    }
                }

                UserProjectEntity lUserProjectEntity;
                if (UserProjectEntityDictionary.TryGetValue(projectEntity.ManufactureNumber, out lUserProjectEntity))
                {
                    projectEntity.UserProjectEntity = lUserProjectEntity;
                    projectEntity.SetIsUserProject(true);
                }

                projectEntity.UserProjectEntityDictionary = UserProjectEntityDictionary;
                if (IsUserProject && !projectEntity.IsUserProject)
                {
                    continue;
                }

                ProjectList.Add(projectEntity);
            }
            if (aLoadOperation.TotalEntityCount != -1)
            {
                this.projectView.SetTotalItemCount(aLoadOperation.TotalEntityCount);
            }
            UpdateChanged("ProjectList");
            this.IsBusy = false;
        }
        /*
        void loadOperationProject_Completed(object sender, EventArgs e)
        {
            ProjectList.Clear();
            LoadOperation loadOperation = sender as LoadOperation;
            foreach (project project in loadOperation.Entities)
            {
                ProjectEntity projectEntity = new ProjectEntity();
                projectEntity.Project = project;
                projectEntity.Update();
                ProjectList.Add(projectEntity);
            }

            UpdateChanged("ProjectList");
            IsBusy = false;
        }
        */
        private ProjectEntity selectProjectEntity = null;
        public ProjectEntity SelectProjectEntity
        {
            get
            {
                return selectProjectEntity;
            }
            set
            {
                if (selectProjectEntity != value)
                {
                    selectProjectEntity = value;
                    UpdateChanged("SelectProjectEntity");
                    (OnFirstImport as DelegateCommand).RaiseCanExecuteChanged();
                    (OnSmallChange as DelegateCommand).RaiseCanExecuteChanged();
                    (OnImportAndChange as DelegateCommand).RaiseCanExecuteChanged();

                    using(planView.DeferRefresh())
                    {
                        this.projectView.MoveToFirstPage();
                    }
                }
            }
        }

        public PlanEditViewModel()
        {
            ProjectList = new ObservableCollection<ProjectEntity>();
            departmentNameIdDictionary = new Dictionary<string, int>();
            departmentIdNameDictionary = new Dictionary<int, string>();
            UserProjectEntityDictionary = new Dictionary<string, UserProjectEntity>();
            importErrorList = new ObservableCollection<string>();

            OnFirstImport = new DelegateCommand(OnFirstImportCommand, CanFirstImport);
            OnSmallChange = new DelegateCommand(OnSmallChangeCommand, CanChange);
            OnImportAndChange = new DelegateCommand(OnImportAndChangeCommand, CanChange);
            DoubleClickProject = new DelegateCommand(DoubleClickProjectCommand);
            OnRefash = new DelegateCommand(OnRefashCommand);
            OnDownloadTemp = new DelegateCommand(OnDownloadTempCommand);

            FilterList = new ObservableCollection<string>();
            FilterList.Add("生产令号");
            FilterList.Add("项目名称");
            FilterList.Add("备注");
            FilterList.Add("年份");
            FilterList.Add("记录时间");
            selectFilerList = "生产令号";
        }

        private int ExcelSheetValidation(Worksheet aSheet,
                                        ref int aFirstValueRow,
                                        ref string aManufactureName,
                                        ref string aVersionId,
                                        ref string aFileId,
                                        ref string aRequirement,
                                        ref Dictionary<string, int> aMatchedColumnDictionary)
        {
            aFirstValueRow = -1;
            ColumnModel columnModel = new ColumnModel();
            foreach (KeyValuePair<int, Row> rowPair in aSheet.Cells.Rows)
            {
                try
                {
                    if (rowPair.Value.LastColIndex < columnModel.MinSize - 1)
                    {
                        Cell cell = rowPair.Value.GetCell(rowPair.Value.FirstColIndex);
                        if (Cell.EmptyCell != cell)
                        {
                            string firstValue = cell.StringValue;
                            string manufactureNumberKey = "生产令号:";
                            string versionIdKey1 = "计划版本:";
                            string versionIdKey2 = "计划版本:";
                            string versionIdKey = string.Empty;
                            int pos = -1;
                            if (-1 != (pos = firstValue.IndexOf(versionIdKey1)))
                            {
                                versionIdKey = versionIdKey1;
                            }
                            else if( -1 != (pos = firstValue.IndexOf(versionIdKey2)))
                            {
                                versionIdKey = versionIdKey2;
                            }

                            if (versionIdKey.Count() > 0)
                            {
                                int versionPos = pos + versionIdKey.Length;
                                aVersionId = firstValue.Substring(versionPos);
                                aVersionId = aVersionId.Trim();
                                string fileIdKey = "文件编号:";
                                int fileIdStartPos = firstValue.IndexOf(fileIdKey);
                                if (-1 != fileIdStartPos)
                                {
                                    fileIdStartPos += fileIdKey.Length;
                                    aFileId = firstValue.Substring(fileIdStartPos, versionPos - fileIdStartPos - versionIdKey.Count());
                                    aFileId = aFileId.Trim();
                                }
                            }
                            else if (-1 != (pos = firstValue.IndexOf(manufactureNumberKey)) && pos < firstValue.Length)
                            {
                                pos += manufactureNumberKey.Length;
                                const char space = ' ';
                                while (space == firstValue[pos])
                                {
                                    ++pos;
                                }

                                int end = firstValue.IndexOf(space, pos);
                                aManufactureName = firstValue.Substring(pos, end - pos);
                                aManufactureName = aManufactureName.Trim();
                                aRequirement = firstValue.Substring(end);
                                aRequirement = aRequirement.Trim();
                            }
                        }
                        continue;
                    }
                }
                catch(Exception e)
                {
                    //empty line
                    continue;
                }
                foreach (ObservableCollection<string> item in columnModel.List)
                {
                    int matchCount = 0;
                    aMatchedColumnDictionary.Clear();
                    for (int column = rowPair.Value.FirstColIndex; column <= rowPair.Value.LastColIndex; ++column)
                    {
                        Cell cell = rowPair.Value.GetCell(column);
                        if (Cell.EmptyCell != cell && item.Contains(cell.StringValue))
                        {
                            aMatchedColumnDictionary.Add(cell.StringValue, column);
                            ++matchCount;
                        }
                    }
                    if (item.Count == matchCount)
                    {
                        aFirstValueRow = rowPair.Key + 1;
                        return columnModel.List.IndexOf(item);
                    }
                }
            }

            return -1;
        }

        private bool CellToPlanExtraEntity(Row aRow, string aManufactureName,
                                        string aFileId, string aRequirement, ref PlanExtraEntity aPlanExtraEntity)
        {
            bool returnValue = false;
            try
            {
                Cell cell = aRow.GetCell(aRow.FirstColIndex);
                if (Cell.EmptyCell != cell)
                {
                    returnValue = true;
                    string firstValue = cell.StringValue;
                    int pos = -1;
                    string compilationBasisKey = "编制依据:";
                    string reasonAdjustment1Key = "第一次调整原因:";
                    string reasonAdjustment2Key = "第二次调整原因:";
                    string compileUser = "编制:";
                    string date = "日期:";
                    if (-1 != (pos = firstValue.IndexOf(compilationBasisKey)))
                    {
                        if (null == aPlanExtraEntity)
                        {
                            aPlanExtraEntity = new PlanExtraEntity();
                            aPlanExtraEntity.ManufactureNumber = aManufactureName;
                            aPlanExtraEntity.FileId = aFileId;
                            aPlanExtraEntity.Requirement = aRequirement;
                        }
                        pos += compilationBasisKey.Count();
                        aPlanExtraEntity.CompilationBasis = firstValue.Substring(pos);
                        aPlanExtraEntity.CompilationBasis = aPlanExtraEntity.CompilationBasis.Trim();
                    }
                    else if (-1 != (pos = firstValue.IndexOf(reasonAdjustment1Key)) && null != aPlanExtraEntity)
                    {
                        pos += reasonAdjustment1Key.Count();
                        aPlanExtraEntity.ReasonAdjustment1 = firstValue.Substring(pos);
                        aPlanExtraEntity.ReasonAdjustment1 = aPlanExtraEntity.ReasonAdjustment1.Trim();
                    }
                    else if (-1 != (pos = firstValue.IndexOf(reasonAdjustment2Key)) && null != aPlanExtraEntity)
                    {
                        pos += reasonAdjustment2Key.Count();
                        aPlanExtraEntity.ReasonAdjustment2 = firstValue.Substring(pos);
                        aPlanExtraEntity.ReasonAdjustment2 = aPlanExtraEntity.ReasonAdjustment2.Trim();
                    }
                    else if (-1 != (pos = firstValue.IndexOf(compileUser)) && null != aPlanExtraEntity)
                    {
                        int startRow = aRow.FirstColIndex + 1;
                        Cell compieUserCell = aRow.GetCell(startRow);
                        if (Cell.EmptyCell != compieUserCell && null != compieUserCell.StringValue)
                        {
                            aPlanExtraEntity.CompileUserName = compieUserCell.StringValue.Trim();
                        }
                        string examineUser = "审核:";
                        string approveUser = "批准:";
                        for (int column = startRow + 1; column <= aRow.LastColIndex; ++column)
                        {
                            Cell elseCell = aRow.GetCell(column);
                            if (Cell.EmptyCell != elseCell && null != elseCell.StringValue && string.Empty != elseCell.StringValue)
                            {
                                int elsePos = -1;
                                if (-1 != ( elsePos = elseCell.StringValue.IndexOf(examineUser)))
                                {
                                    ++column;
                                    elseCell = aRow.GetCell(column);
                                    if (Cell.EmptyCell != elseCell && null != elseCell.StringValue)
                                    {
                                        aPlanExtraEntity.ExamineUserName = elseCell.StringValue.Trim();
                                    }
                                }
                                else if (-1 != (elsePos = elseCell.StringValue.IndexOf(approveUser)))
                                {
                                    ++column;
                                    elseCell = aRow.GetCell(column);
                                    if (Cell.EmptyCell != elseCell && null != elseCell.StringValue)
                                    {
                                        aPlanExtraEntity.ApproveUserName = elseCell.StringValue.Trim();
                                    }
                                }
                            }
                        }
                    }
                    else if (-1 != (pos = firstValue.IndexOf(date)) && null != aPlanExtraEntity)
                    {
                        int startRow = aRow.FirstColIndex + 1;
                        Cell compieDateCell = aRow.GetCell(startRow);
                        if (Cell.EmptyCell != compieDateCell && null != compieDateCell.StringValue && string.Empty != compieDateCell.StringValue)
                        {
                            aPlanExtraEntity.CompileDate = compieDateCell.DateTimeValue;
                        }

                        bool secondSet = false;
                        bool thirdSet = false;
                        for (int column = startRow + 1; column <= aRow.LastColIndex; ++column)
                        {
                            Cell elseCell = aRow.GetCell(column);
                            if (Cell.EmptyCell != elseCell && null != elseCell.StringValue && string.Empty != elseCell.StringValue)
                            {
                                int elsePos = -1;
                                if (-1 != (elsePos = elseCell.StringValue.IndexOf(date)))
                                {
                                    ++column;
                                    elseCell = aRow.GetCell(column);
                                    if (Cell.EmptyCell != elseCell && null != elseCell.StringValue && string.Empty != elseCell.StringValue)
                                    {
                                        if (!secondSet)
                                        {
                                            aPlanExtraEntity.ExamineDate = elseCell.DateTimeValue;
                                            secondSet = true;
                                        }
                                        else if (!thirdSet)
                                        {
                                            aPlanExtraEntity.ApproveDate = elseCell.DateTimeValue;
                                            thirdSet = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        returnValue = false;
                    }
                }
            }
            catch (Exception e)
            {

            }
            return returnValue;
        }

        private PlanEntity ExcelRowToPlanEntity(string aSheetName, int aRowNumber, Row aExcelRow, Dictionary<string, int> aMatchedColumnDictionary,
                            ref string aLastComponentName)
        {
            do
            {
                PlanEntity planEntity = new PlanEntity();
                int getValue = 0;
                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("序号", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效序号" ;
                        importErrorList.Add(lError);
                        break;
                    }
                    planEntity.SequenceId = Convert.ToInt32(cell.StringValue);
                }

                int taskDescriptionColumn = -1;
                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("任务描述", out taskDescriptionColumn)
                        && -1 != taskDescriptionColumn
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(taskDescriptionColumn)))
                    {
                        planEntity.TaskDescription = cell.StringValue;
                    }
                }

                {
                    Cell cell1 = Cell.EmptyCell;
                    Cell cell2 = Cell.EmptyCell;
                    if ((!aMatchedColumnDictionary.TryGetValue("部件", out getValue)
                         || -1 == getValue
                         || (Cell.EmptyCell == (cell1 = aExcelRow.GetCell(getValue))
                             & Cell.EmptyCell == (cell2 = aExcelRow.GetCell(getValue + 1))))
                        && string.Empty == aLastComponentName)
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效部件";
                        importErrorList.Add(lError);
                        break;
                    }

                    if (Cell.EmptyCell != cell1)
                    {
                        planEntity.ComponentName = cell1.StringValue;
                    }

                    if (getValue + 1 != taskDescriptionColumn && Cell.EmptyCell != cell2)
                    {
                        planEntity.ComponentName += cell2.StringValue;
                    }

                    if (null == planEntity.ComponentName)
                    {
                        planEntity.ComponentName = string.Empty;
                    }

                    if (string.Empty == planEntity.ComponentName)
                    {
                        planEntity.ComponentName = aLastComponentName;
                    }
                    else
                    {
                        aLastComponentName = planEntity.ComponentName;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("权重(分值)", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效权重";
                        importErrorList.Add(lError);
                        break;
                    }
                    planEntity.Weight = Convert.ToDecimal(cell.StringValue);
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("实际得分", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.Score = Convert.ToDecimal(cell.StringValue);
                        }
                        catch(FormatException e )
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("计划完成时间", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        if (!aMatchedColumnDictionary.TryGetValue("计划到货时间", out getValue)
                            || -1 == getValue
                            || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                        {
                            string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效计划时间";
                            importErrorList.Add(lError);
                            break;
                        }
                    }
                    try
                    {
                        planEntity.TargetDate = cell.DateTimeValue;
                    }
                    catch (FormatException e)
                    {
                        //ignore exception
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划第一次调整", out getValue)
                         || aMatchedColumnDictionary.TryGetValue("第一次调整", out getValue))
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.TargetDateAdjustment1 = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划第二次调整", out getValue)
                         || aMatchedColumnDictionary.TryGetValue("第二次调整", out getValue))
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.TargetDateAdjustment2 = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("实际完成时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue)
                        || (aMatchedColumnDictionary.TryGetValue("实际到货时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue))
                    {
                        try
                        {
                            planEntity.AccomplishDate = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    int getDepartmentId = -1;
                    if (aMatchedColumnDictionary.TryGetValue("责任单位", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue
                        && departmentNameIdDictionary.TryGetValue(cell.StringValue, out getDepartmentId))
                    {
                        planEntity.DepartmentId = getDepartmentId;
                        planEntity.DepartmentName = cell.StringValue;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("备注", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue)))
                    {
                        planEntity.Remark = cell.StringValue;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划下订单时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue))
                    {
                        try
                        {
                            planEntity.OrderDate = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                return planEntity;
            } while (false);
            return null;
        }

        public ICommand OnFirstImport { get; private set; }

        public ICommand OnSmallChange { get; private set; }

        public ICommand OnImportAndChange { get; private set; }

        public ICommand DoubleClickProject { get; private set; }

        public ICommand OnRefash { get; private set; }

        public ICommand OnDownloadTemp { get; private set; }

        private void OnRefashCommand()
        {
            selectProjectEntity = null;
            //ProductEntityList.Clear();
            //ProjectResponsibleEntityList.Clear();
            using (this.CollectionProjectView.DeferRefresh())
            {
                this.projectView.MoveToFirstPage();
            }
            (OnFirstImport as DelegateCommand).RaiseCanExecuteChanged();
            (OnSmallChange as DelegateCommand).RaiseCanExecuteChanged();
            (OnImportAndChange as DelegateCommand).RaiseCanExecuteChanged();
        }

        private void DoubleClickProjectCommand()
        {
            if (null != SelectProjectEntity)
            {
                if (String.IsNullOrEmpty(SelectProjectEntity.PlanVersionID))
                {
                    OnFirstImportCommand();
                }
                else
                {
                    OnSmallChangeCommand();
                }
            }
        }

        private bool CanFirstImport(object aObject)
        {
            return null != SelectProjectEntity
                && (null == SelectProjectEntity.PlanVersionID
                    || string.Empty == SelectProjectEntity.PlanVersionID);
        }

        private bool CanChange(object aObject)
        {
            return null != SelectProjectEntity
                && null != SelectProjectEntity.PlanVersionID
                && string.Empty != SelectProjectEntity.PlanVersionID;
        }

        private void OnFirstImportCommand()
        {
            IsBusy = true;
            OpenFileDialog oFile = new OpenFileDialog();
            // .xls filter specified to select only .xls file.
            oFile.Filter = "Excel (*.xls)|*.xls";

            if (oFile.ShowDialog() == true)
            {
                ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                string getVersionId = string.Empty;
                string errorMessage = string.Empty;
                string getFileId = string.Empty;
                string lastVersionId = string.Empty;
                string getRequirement = string.Empty;
                PlanExtraEntity planExtraEntity = null;
                importErrorList.Clear();

                try
                {
                    FileStream fs = oFile.File.OpenRead();
                    Workbook book = Workbook.Open(fs);
                    for (int loop = 0; loop < book.Worksheets.Count; ++loop)
                    {
                        if ("设计完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "设计节点";
                        }
                        else if ("采购完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "采购节点";
                        }
                        else if ("生产完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "生产节点";
                        }
                        int firstValueRow = -1;
                        string getManufactureName = string.Empty;
                        Dictionary<string, int> matchedColumnDictionary = new Dictionary<string, int>();
                        int modelIndex = -1;
                        if (-1 == (modelIndex = ExcelSheetValidation(book.Worksheets[loop], ref firstValueRow, ref getManufactureName,
                                                ref getVersionId, ref getFileId, ref getRequirement, ref matchedColumnDictionary)))
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "格式与模板不匹配;\r\n";
                            continue;
                        }

                        if (string.Empty == getVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "解析版本号失败;\r\n";
                            continue;
                        }

                        if (string.Empty != lastVersionId && getVersionId != lastVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号与上页不一致;\r\n";
                            continue;
                        }
                        lastVersionId = getVersionId;

                        if (SelectProjectEntity.ManufactureNumber.TrimEnd() != getManufactureName)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "生产令号不正确;\r\n";
                            continue;
                        }

                        var lResult = from c in planManagerDomainContext.plans
                                      where c.version_id == getVersionId
                                      && c.manufacture_number == getManufactureName
                                      select c;
                        if (0 != lResult.Count())
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号重复;\r\n";
                            continue;
                        }

                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        string lastComponentName = string.Empty;
                        ObservableCollection<int> sequenceIdList = new ObservableCollection<int>();
                        foreach (KeyValuePair<int, Row> rowPair in book.Worksheets[loop].Cells.Rows)
                        {
                            try
                            {
                                if ( rowPair.Key < firstValueRow
                                    || CellToPlanExtraEntity(rowPair.Value, getManufactureName, getFileId, getRequirement, ref planExtraEntity)
                                    || rowPair.Value.LastColIndex < 1)
                                {
                                    //不允许穿插
                                    continue;
                                }
                            }
                            catch (Exception e)
                            {
                                //empty line
                                continue;
                            }

                            PlanEntity planEntity = ExcelRowToPlanEntity(book.Worksheets[loop].Name, rowPair.Key, rowPair.Value, matchedColumnDictionary, ref lastComponentName);
                            if (null != planEntity)
                            {
                                while (sequenceIdList.Contains(planEntity.SequenceId))
                                {
                                    planEntity.SequenceId++;
                                }
                                sequenceIdList.Add(planEntity.SequenceId);

                                planEntity.ProjectName = SelectProjectEntity.ProjectName;
                                planEntity.VersionId = getVersionId;
                                planEntity.ManufactureNumber = getManufactureName;
                                planEntity.SheetName = book.Worksheets[loop].Name;
                                planList.Add(planEntity);
                            }
                        }

                        if(planList.Count > 0)
                        {
                            PlanListViewModel planListViewModel = new PlanListViewModel(book.Worksheets[loop].Name, planList,
                                                                      modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }

                    if (string.Empty == errorMessage && 0 == planListViewModelList.Count)
                    {
                        errorMessage = "无效文件 " + oFile.File.Name + "\r\n";
                    }
                    else
                    {
                        foreach (string value in importErrorList)
                        {
                            errorMessage += (value + "\r\n");
                        }
                        importErrorList.Clear();
                    }
                }
                catch (Exception e)
                {
                    errorMessage = e.Message + "\r\n";
                }

                if (planListViewModelList.Count > 0)
                {
                    string title = "初次入库(";
                    title += SelectProjectEntity.ProjectName;
                    title += " ";
                    title += SelectProjectEntity.ManufactureNumber;
                    title += " ";
                    title += getVersionId;
                    title += ")";
                    if (null != planExtraEntity)
                    {
                        planExtraEntity.VersionId = getVersionId;
                    }
                    PlanListEditWindow planListWindow = new PlanListEditWindow(title, "入库", getVersionId, planListViewModelList, planExtraEntity);
                    planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                    planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                    planListWindow.Show();

                    if (string.Empty != errorMessage)
                    {
                        Message.InfoMessage(errorMessage);
                    }
                }
                else
                {
                    Message.ErrorMessage(errorMessage);
                }
            }

            IsBusy = false;
        }

        void PlanListWindow_Closed(object sender, EventArgs e)
        {
            PlanListEditWindow planListWindow = sender as PlanListEditWindow;
            if (planListWindow.DialogResult == true)
            {
                int isAccomplished = 1;
                bool newPlans = false;
                int maxVersion = 0;
                for (int pos = 0; pos < planListWindow.planListViewModelList.Count; ++pos)
                {
                    PlanListViewModel planListViewModel = planListWindow.planListViewModelList[pos];
                    for (int planpos = 0; planpos < planListViewModel.PlanList.Count; ++planpos)
                    {
                        PlanEntity planEntity = planListViewModel.PlanList[planpos];
                        newPlans = (newPlans | planEntity.IsNew());

                        if (maxVersion < 1 && planEntity.TargetDateAdjustment1.HasValue)
                        {
                            maxVersion = 1;
                        }
                        else if (maxVersion < 2 && planEntity.TargetDateAdjustment2.HasValue)
                        {
                            maxVersion = 2;
                        }
                    }
                }

                string lNewVersionId = planListWindow.VersionId;
                if (newPlans)
                {
                    string titleString = planListWindow.Title as string;
                    if (-1 != titleString.IndexOf("少量修改"))
                    {
                        newPlans = false;
                        int lLeftPos = lNewVersionId.IndexOf('.') + 1;
                        string lDecimal = lNewVersionId.Substring(lLeftPos);
                        int lNumber = Convert.ToInt32(lDecimal);
                        if (lNumber < maxVersion)
                        {
                            newPlans = true;
                            if (1 == maxVersion)
                            {
                                lNewVersionId = lNewVersionId.Substring(0, lLeftPos) + Convert.ToString(maxVersion);
                            }
                            else
                            {
                                lNewVersionId = lNewVersionId.Substring(0, lLeftPos) + Convert.ToString(maxVersion);
                            }
                        }
                    }
                    planListWindow.VersionId = lNewVersionId;
                }

                for(int pos = 0; pos < planListWindow.planListViewModelList.Count; ++pos)
                {
                    PlanListViewModel planListViewModel = planListWindow.planListViewModelList[pos];
                    for(int planpos = 0; planpos < planListViewModel.PlanList.Count; ++planpos)
                    {
                        PlanEntity planEntity = planListViewModel.PlanList[planpos];
                        if (null == planEntity.AccomplishDate)
                        {
                            isAccomplished = 0;
                        }

                        planEntity.VersionId = planListWindow.VersionId;
                        if (newPlans)
                        {
                            planEntity.Plan = null;
                        }
                        bool lTempNew = (null == planEntity.Plan);
                        planEntity.DUpdate();
                        if (newPlans || lTempNew)
                        {
                            planManagerDomainContext.plans.Add(planEntity.Plan);
                        }
                    }

                    for (int deletePos = 0; deletePos < planListViewModel.DeletedPlanList.Count; ++deletePos)
                    {
                        PlanEntity planEntity = planListViewModel.DeletedPlanList[deletePos];
                        if (null != planEntity.Plan)
                        {
                            planManagerDomainContext.plans.Remove(planEntity.Plan);
                        }
                    }
                }

                App app = Application.Current as App;
                if(null != planListWindow.planExtraEntity)
                {
                    planListWindow.planExtraEntity.VersionId = planListWindow.VersionId;
                    planListWindow.planExtraEntity.CompileUserName = app.UserInfo.UserName;
                    planListWindow.planExtraEntity.CompileDate = DateTime.Now;
                    if (newPlans)
                    {
                        planListWindow.planExtraEntity.PlanExtra = null;
                    }
                    planListWindow.planExtraEntity.DUpdate();
                    if (newPlans)
                    {
                        planManagerDomainContext.plan_extras.Add(planListWindow.planExtraEntity.PlanExtra);
                    }
                }

                SelectProjectEntity.CompileUserName = app.UserInfo.UserName;
                SelectProjectEntity.CompileDate = DateTime.Now;
                SelectProjectEntity.AccomplishMark = isAccomplished;
                SelectProjectEntity.PlanVersionID = planListWindow.VersionId;
                SelectProjectEntity.PlanUpdateDate = DateTime.Now;
                SelectProjectEntity.DUpdate();

                SubmitOperation submitOperation = planManagerDomainContext.SubmitChanges();
                submitOperation.Completed += SubmitOperation_Completed;
            }
            (OnFirstImport as DelegateCommand).RaiseCanExecuteChanged();
            (OnSmallChange as DelegateCommand).RaiseCanExecuteChanged();
            (OnImportAndChange as DelegateCommand).RaiseCanExecuteChanged();
        }

        void SubmitOperation_Completed(object sender, EventArgs e)
        {
            SubmitOperation submitOperation = sender as SubmitOperation;
            if (submitOperation.HasError)
            {
                submitOperation.MarkErrorAsHandled();
                Message.ErrorMessage("失败!");
            }
            else
            {
                Message.InfoMessage("成功!");
                OnRefashCommand();
            }
        }

        private bool GetNewVersionId(string aManufactureNumber, ref string aNewVersionID)
        {
            bool getNewVersionId = false;
            string lastVersionId = aNewVersionID;
            int pos = lastVersionId.IndexOf('.');
            if (-1 != pos && ++pos < lastVersionId.Length)
            {
                int currentSubVersion = Convert.ToInt32(lastVersionId.Substring(pos));
                while (!getNewVersionId && currentSubVersion < ushort.MaxValue)
                {
                    ++currentSubVersion;
                    lastVersionId = lastVersionId.Substring(0, pos) + Convert.ToString(currentSubVersion);
                    IEnumerable<string> versionIds = from c in planManagerDomainContext.plans
                                                     where c.version_id == lastVersionId
                                                     && c.manufacture_number == aManufactureNumber
                                                     select c.version_id;

                    if (0 == versionIds.Count())
                    {
                        getNewVersionId = true;
                        aNewVersionID = lastVersionId;
                        break;
                    }
                }
            }
            return getNewVersionId;
        }

        private void OnSmallChangeCommand()
        {
            IsBusy = true;

            if (null == SelectProjectEntity.PlanVersionID
                || null == SelectProjectEntity.ManufactureNumber
                || string.Empty == SelectProjectEntity.PlanVersionID
                || string.Empty == SelectProjectEntity.ManufactureNumber)
            {
                Message.ErrorMessage("生产令号或版本号无效");
            }
            else
            {
                string newVersionId = SelectProjectEntity.PlanVersionID;
//                 if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId))
//                 {
//                     Message.ErrorMessage("生成新版本号失败");
//                     IsBusy = false;
//                     return;
//                 }

                IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                                 where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                select c.sheet_name;
                if (sheetNames.Count() > 0)
                {
                    ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                    ObservableCollection<string> differentSheets = new ObservableCollection<string>();
                    foreach (string originalValue in sheetNames)
                    {
                        if (null == originalValue)
                        {
                            continue;
                        }
                        string value = originalValue;

                        if ("设计完成节点" == value)
                        {
                            value = "设计节点";
                        }
                        else if ("采购完成节点" == value)
                        {
                            value = "采购节点";
                        }
                        else if ("生产完成节点" == value)
                        {
                            value = "生产节点";
                        }

                        if (differentSheets.Contains(value))
                        {
                            continue;
                        }
                        differentSheets.Add(value);
                        IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                  where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                    && c.sheet_name == originalValue orderby c.sequence_id
                                                  select c;
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        bool hasOrderDate = false;
                        for (int pos = 0; pos < selectedPlans.Count<plan>(); ++pos)
                        {
                            plan item = selectedPlans.ElementAt(pos); ;
                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = item;
                            if (item.order_date.HasValue)
                            {
                                hasOrderDate = true;
                            }
                            string getDepartmentName = string.Empty;
                            planEntity.Update();
 //                           planEntity.Plan = null;
 //                           planEntity.VersionId = newVersionId;
                            planEntity.ProjectName = SelectProjectEntity.ProjectName;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planList.Add(planEntity);
                        }
                        if (planList.Count > 0)
                        {
                            int modelIndex = -1;
                            if ("采购节点" == planList[0].SheetName)
                            {
                                if (hasOrderDate)
                                {
                                    modelIndex = 1;
                                }
                                else
                                {
                                    modelIndex = 2;
                                }
                            }
                            else
                            {
                                modelIndex = 0;
                            }

                            PlanListViewModel planListViewModel = new PlanListViewModel(value, planList,
                                                                    modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsChanged = false;
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }
                    if (planListViewModelList.Count > 0)
                    {
                        string title = "少量修改(";
                        title += SelectProjectEntity.ProjectName;
                        title += " ";
                        title += SelectProjectEntity.ManufactureNumber.TrimEnd();
                        title += " ";
                        title += newVersionId;
                        title += ")";
                        PlanExtraEntity planExtraEntity = null;
                        IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras
                                                              where c.version_id == SelectProjectEntity.PlanVersionID
                                                                && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                                select c;
                        if (0 != plan_extras.Count())
                        {
                            planExtraEntity = new PlanExtraEntity();
                            planExtraEntity.PlanExtra = plan_extras.First<plan_extra>();
                            planExtraEntity.Update();
//                             planExtraEntity.VersionId = newVersionId;
//                             planExtraEntity.PlanExtra = null;
                        }
                        PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", newVersionId, planListViewModelList, planExtraEntity);
                        planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                        planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                        planListWindow.Show();
                    }
                }
                else
                {
                    string errorMessage = "无相关数据(生产令号:" +
                                            SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                            ",版本号" +
                                            SelectProjectEntity.PlanVersionID
                                            + ")" + "\r\n"; ;
                    Message.ErrorMessage(errorMessage);
                }
            }

            IsBusy = false;
        }

        private void OnImportAndChangeCommand()
        {
            IsBusy = true;
//             string newVersionId = SelectProjectEntity.PlanVersionID;
//             if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId))
//             {
//                 Message.ErrorMessage("生成新版本号失败");
//                 IsBusy = false;
//                 return;
//             }

            OpenFileDialog oFile = new OpenFileDialog();
            // .xls filter specified to select only .xls file.
            oFile.Filter = "Excel (*.xls)|*.xls";

            if (oFile.ShowDialog() == true)
            {
                ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                string excelVersionId = string.Empty;
                string errorMessage = string.Empty;
                string lastVersionId = string.Empty;
                string getFileId = string.Empty;
                string getRequirement = string.Empty;
                PlanExtraEntity planExtraEntity = null;
                importErrorList.Clear();

                try
                {
                    FileStream fs = oFile.File.OpenRead();
                    Workbook book = Workbook.Open(fs);
                    for (int loop = 0; loop < book.Worksheets.Count; ++loop)
                    {
                        if ("设计完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "设计节点";
                        }
                        else if ("采购完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "采购节点";
                        }
                        else if ("生产完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "生产节点";
                        }
                        int firstValueRow = -1;
                        string getManufactureName = string.Empty;
                        int modelIndex = -1;
                        Dictionary<string, int> matchedColumnDictionary = new Dictionary<string, int>();
                        if (-1 == (modelIndex = ExcelSheetValidation(book.Worksheets[loop], ref firstValueRow,  ref getManufactureName,
                                                                    ref excelVersionId, ref getFileId, ref getRequirement, ref matchedColumnDictionary)))
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "格式与模板不匹配;\r\n";
                            continue;
                        }

                        if (string.Empty == excelVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "解析版本号失败;\r\n";
                            continue;
                        }

                        if (string.Empty != lastVersionId && excelVersionId != lastVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号与上页不一致;\r\n";
                            continue;
                        }

                        if (SelectProjectEntity.ManufactureNumber.TrimEnd() != getManufactureName)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "生产令号不正确;\r\n";
                            continue;
                        }

                        var lResult = from c in planManagerDomainContext.plans
                                      where c.version_id == excelVersionId
                                      && c.manufacture_number == getManufactureName
                                      select c;
                        if (0 != lResult.Count())
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号重复;\r\n";
                            continue;
                        }
                        lastVersionId = excelVersionId;

                        ObservableCollection<int> sequenceIdList = new ObservableCollection<int>();
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        string lastComponentName = string.Empty;
                        foreach (KeyValuePair<int, Row> rowPair in book.Worksheets[loop].Cells.Rows)
                        {
                            try
                            {
                                if (rowPair.Key < firstValueRow
                                    || CellToPlanExtraEntity(rowPair.Value, getManufactureName, getFileId, getRequirement, ref planExtraEntity)
                                    || rowPair.Value.LastColIndex < 1)
                                {
                                    //不允许穿插
                                    continue;
                                }
                            }
                            catch (Exception e)
                            {
                                //empty line
                                continue;
                            }

                            PlanEntity planEntity = ExcelRowToPlanEntity(book.Worksheets[loop].Name, rowPair.Key, rowPair.Value, matchedColumnDictionary, ref lastComponentName);
                            if (null != planEntity)
                            {
                                while (sequenceIdList.Contains(planEntity.SequenceId))
                                {
                                    planEntity.SequenceId++;
                                }
                                sequenceIdList.Add(planEntity.SequenceId);

                                planEntity.VersionId = excelVersionId;
                                planEntity.ManufactureNumber = getManufactureName;
                                planEntity.SheetName = book.Worksheets[loop].Name;
                                planList.Add(planEntity);
                            }
                        }

                        if (planList.Count > 0)
                        {
                            PlanListViewModel planListViewModel = new PlanListViewModel(book.Worksheets[loop].Name, planList,
                                                                      modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }

                    if (string.Empty == errorMessage && 0 == planListViewModelList.Count)
                    {
                        errorMessage = "无效文件 " + oFile.File.Name + "\r\n";
                    }
                    else
                    {
                        foreach (string value in importErrorList)
                        {
                            errorMessage += (value + "\r\n");
                        }
                        importErrorList.Clear();
                    }
                }
                catch (Exception e)
                {
                    errorMessage = e.Message;
                }

                if (planListViewModelList.Count > 0)
                {
                    string title = "大量修改(";
                    title += SelectProjectEntity.ProjectName;
                    title += " ";
                    title += SelectProjectEntity.ManufactureNumber;
                    title += " ";
                    title += excelVersionId;
                    title += ")";
                    if (null != planExtraEntity)
                    {
                        planExtraEntity.VersionId = excelVersionId;
                    }
                    PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", excelVersionId, planListViewModelList, planExtraEntity);
                    planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                    planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                    planListWindow.Show();

                    if (string.Empty != errorMessage)
                    {
                        Message.InfoMessage(errorMessage);
                    }
                }
                else
                {
                    Message.ErrorMessage(errorMessage);
                }
            }
            IsBusy = false;
        }

        private SaveFileDialog saveFileDialog;

        private void OnDownloadTempCommand()
        {
            String FileUrl = CustomUri.GetAbsoluteUrl("ProductmanagerFileTemp/计划模版.xls");

            try
            {
                saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "All Files|*.*";
                saveFileDialog.GetType().GetMethod("set_DefaultFileName").Invoke(saveFileDialog, new object[] { "计划模版.xls" });
                bool? dialogResult = saveFileDialog.ShowDialog();
                if (dialogResult != true) return;
                WebClient client = new WebClient();
                Uri uri = new Uri(FileUrl, UriKind.RelativeOrAbsolute);
                client.OpenReadCompleted += new OpenReadCompletedEventHandler(OpenReadCompleted);
                client.OpenReadAsync(uri);
            }
            catch (System.Exception ex)
            {
                NotifyWindow notifyWindow = new NotifyWindow("下载错误", ex.Message);
                notifyWindow.Show();
            }
        }

        void OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                using (Stream sf = (Stream)saveFileDialog.OpenFile())
                {
                    e.Result.CopyTo(sf);
                    sf.Flush();
                    sf.Close();
                    NotifyWindow notifyWindow = new NotifyWindow("下载完成", "下载完成!");
                    notifyWindow.Show();
                }
            }
            else
            {
                NotifyWindow notifyWindow = new NotifyWindow("下载错误", e.Error.Message);
                notifyWindow.Show();
            }
        }
    }
}


text:
<?php

namespace CallFire\Api\Rest\Request;

use CallFire\Api\Rest\Request as AbstractRequest;

class UnlabelBroadcast extends AbstractRequest
{

    /**
     * Label name
     */
    protected $labelName = null;

    public function getLabelName()
    {
        return $this->labelName;
    }

    public function setLabelName($labelName)
    {
        $this->labelName = $labelName;

        return $this;
    }

}