private void btnNext_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            DataGridViewRow row=null;
            int c = 0;
            do
            {
               c= r.Next(c, dgvCustomer.Rows.Count - 1);
                row = dgvCustomer.Rows[c];

            } while (row.Cells["colUploadInd"].Value.ToString() == "Y");
            string id = row.Cells["colId"].Value.ToString();
            _customer = NHibernateHelper.Load<CustomerModel>(id);
            updateCustomerUI();
        }
        public void importCustomer()
        {
            ExcelHelper eh = new ExcelHelper(this.txtFilePath.Text);
            String name = eh.GetSheetNames().ElementAt(0);
            DataSet ds = eh.ExcelToDataSet(name);
            System.Data.DataTable dt = ds.Tables[0];
            Dictionary<string, IList<ShopModel>> dictCityShops = new Dictionary<string, IList<ShopModel>>();

            ICriteria icr = NHibernateHelper.CreateCriteria<DictModel>();
            icr.Add(Restrictions.Eq("type", DictModel.Type.drive_cs.ToString()));
            IList<DictModel> drivercss = icr.List<DictModel>();

            icr = NHibernateHelper.CreateCriteria<DictModel>();
            icr.Add(Restrictions.Eq("type", DictModel.Type.buy_time.ToString()));
            IList<DictModel> buytimes = icr.List<DictModel>();
            Random random = new Random();
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                tsslState.Text = string.Format("数据导入({0}/{1})", ++i, dt.Rows.Count);
                CustomerModel customer = new CustomerModel();
                customer.name = dr[0].ToString();
                customer.mobile = dr[1].ToString();
                customer.city = dr[2].ToString();

                String region = dr[3].ToString();

                if (!string.IsNullOrEmpty(customer.city))
                {
                    IList<ShopModel> shops = null;
                    if (dictCityShops.ContainsKey(customer.city))
                    {
                        shops = dictCityShops[customer.city];
                    }
                    else
                    {
                        icr = NHibernateHelper.CreateCriteria<ShopModel>();
                        icr.Add(Restrictions.Like("city", "%" + customer.city + "%"));
                        shops = icr.List<ShopModel>();
                        dictCityShops.Add(customer.city, shops);
                    }
                    if (shops.Count > 0)
                    {
                        customer.province = shops[0].province;

                        if (!string.IsNullOrEmpty(region))
                        {
                            icr = NHibernateHelper.CreateCriteria<ShopModel>();
                            icr.Add(Restrictions.Like("city", "%" + customer.city + "%"));
                            icr.Add(Restrictions.Or(Restrictions.Like("smallRegion", "%" + region + "%"), Restrictions.Like("address", "%" + region + "%")));
                            IList<ShopModel> shops1 = icr.List<ShopModel>();
                            if (shops1.Count > 0)
                            {
                                customer.shop = shops1[random.Next(0, shops1.Count - 1)].name;
                            }
                            else
                            {
                                customer.shop = shops[random.Next(0, shops.Count - 1)].name;
                            }
                        }
                        else
                        {

                            customer.shop = shops[random.Next(0, shops.Count - 1)].name;
                        }

                    }

                    customer.buytime = buytimes[random.Next(0, buytimes.Count - 1)].value;
                    customer.drivecs = drivercss[random.Next(0, drivercss.Count - 1)].value;
                    customer.uploadInd = "N";
                }

                customer.createPk();
                JsResultObject re = Toyz4net.Core.Util.NHibernateHelper.SaveOrUpdate(customer, "");
                String msg = re.msg;
            }
        }
        private void dgvCustomer_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewRow row = dgvCustomer.Rows[e.RowIndex];

                _customer = new CustomerModel();
                string id = row.Cells[0].Value.ToString();
                _customer = NHibernateHelper.Load<CustomerModel>(id);
                if (_customer != null)
                {
                    updateCustomerUI();
                }
            }
            catch (Exception ex) { return; }
        }
Example #4
0
        public void importCustomer()
        {
            ExcelHelper eh   = new ExcelHelper(this.txtFilePath.Text);
            String      name = eh.GetSheetNames().ElementAt(0);
            DataSet     ds   = eh.ExcelToDataSet(name);

            System.Data.DataTable dt = ds.Tables[0];
            Dictionary <string, IList <ShopModel> > dictCityShops = new Dictionary <string, IList <ShopModel> >();

            ICriteria icr = NHibernateHelper.CreateCriteria <DictModel>();

            icr.Add(Restrictions.Eq("type", DictModel.Type.drive_cs.ToString()));
            IList <DictModel> drivercss = icr.List <DictModel>();

            icr = NHibernateHelper.CreateCriteria <DictModel>();
            icr.Add(Restrictions.Eq("type", DictModel.Type.buy_time.ToString()));
            IList <DictModel> buytimes = icr.List <DictModel>();
            Random            random   = new Random();
            int i = 0;

            foreach (DataRow dr in dt.Rows)
            {
                tsslState.Text = string.Format("数据导入({0}/{1})", ++i, dt.Rows.Count);
                CustomerModel customer = new CustomerModel();
                customer.name   = dr[0].ToString();
                customer.mobile = dr[1].ToString();
                customer.city   = dr[2].ToString();

                String region = dr[3].ToString();



                if (!string.IsNullOrEmpty(customer.city))
                {
                    IList <ShopModel> shops = null;
                    if (dictCityShops.ContainsKey(customer.city))
                    {
                        shops = dictCityShops[customer.city];
                    }
                    else
                    {
                        icr = NHibernateHelper.CreateCriteria <ShopModel>();
                        icr.Add(Restrictions.Like("city", "%" + customer.city + "%"));
                        shops = icr.List <ShopModel>();
                        dictCityShops.Add(customer.city, shops);
                    }
                    if (shops.Count > 0)
                    {
                        customer.province = shops[0].province;

                        if (!string.IsNullOrEmpty(region))
                        {
                            icr = NHibernateHelper.CreateCriteria <ShopModel>();
                            icr.Add(Restrictions.Like("city", "%" + customer.city + "%"));
                            icr.Add(Restrictions.Or(Restrictions.Like("smallRegion", "%" + region + "%"), Restrictions.Like("address", "%" + region + "%")));
                            IList <ShopModel> shops1 = icr.List <ShopModel>();
                            if (shops1.Count > 0)
                            {
                                customer.shop = shops1[random.Next(0, shops1.Count - 1)].name;
                            }
                            else
                            {
                                customer.shop = shops[random.Next(0, shops.Count - 1)].name;
                            }
                        }
                        else
                        {
                            customer.shop = shops[random.Next(0, shops.Count - 1)].name;
                        }
                    }

                    customer.buytime   = buytimes[random.Next(0, buytimes.Count - 1)].value;
                    customer.drivecs   = drivercss[random.Next(0, drivercss.Count - 1)].value;
                    customer.uploadInd = "N";
                }

                customer.createPk();
                JsResultObject re  = Toyz4net.Core.Util.NHibernateHelper.SaveOrUpdate(customer, "");
                String         msg = re.msg;
            }
        }