コード例 #1
0
ファイル: ExcelToAccess.cs プロジェクト: tengdahuang/CaiHong
        public static void ImportToAccess(string tableName)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataSet ds      = new DataSet();
                string  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ofd.FileName + ";" +
                                  "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string           strExcel  = "";
                OleDbDataAdapter myCommand = null;
                strExcel  = string.Format("select * from [{0}$]", "Sheet1"); //Sheet1为excel中工作薄
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                myCommand.Fill(ds, "Sheet1");
                DataTable dt = ds.Tables["Sheet1"];

                for (int iRow = 1; iRow < dt.Rows.Count; iRow++)
                {
                    BaseInfoMember bifm = BaseInfoMember.New;
                    bifm.CardNumber      = dt.Rows[iRow][0].ToString();
                    bifm.MemberName      = dt.Rows[iRow][1].ToString();
                    bifm.PinYin          = AutoPinYin.GetPinYin(bifm.MemberName);
                    bifm.Password        = dt.Rows[iRow][3].ToString();
                    bifm.Birth           = (DateTime)dt.Rows[iRow][4];
                    bifm.Mobile          = dt.Rows[iRow][5].ToString();
                    bifm.Phone           = dt.Rows[iRow][6].ToString();
                    bifm.DiscountRate    = (decimal)dt.Rows[iRow][7];
                    bifm.RemainingSum    = (decimal)dt.Rows[iRow][8];
                    bifm.TotalBonusPoint = (decimal)dt.Rows[iRow][9];
                    bifm.Frequency       = (decimal)dt.Rows[iRow][10];
                    bifm.TotalSpending   = (decimal)dt.Rows[iRow][11];
                    bifm.Description     = dt.Rows[iRow][12].ToString();
                    bifm.SavedOn         = (DateTime)dt.Rows[iRow][13];
                    bifm.OptrType        = UserStatics.OptrType;
                    bifm.Save();
                }


                //DbEntry.Context.UsingConnection(delegate()
                //{
                //    IDbBulkCopy c = DbEntry.Context.GetDbBulkCopy();
                //    c.BatchSize = 10;
                //    c.DestinationTableName = tableName;
                //    c.NotifyAfter = 10;
                //    //c.SqlRowsCopied += new SqlRowsCopiedEventHandler(
                //    //    delegate(object sender, SqlRowsCopiedEventArgs e)
                //    //    {
                //    //        Console.WriteLine("{0} rows copied.", e.RowsCopied);
                //    //    });
                //    c.WriteToServer(dt);
                //});
            }
        }
コード例 #2
0
        public void ImportToAccess()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataSet ds      = new DataSet();
                string  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ofd.FileName + ";" +
                                  "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string           strExcel  = "";
                OleDbDataAdapter myCommand = null;
                strExcel  = string.Format("select * from [{0}$]", "Sheet1"); //Sheet1为excel中工作薄
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                myCommand.Fill(ds, "Sheet1");
                DataTable dt = ds.Tables["Sheet1"];

                Encoding gb2312 = Encoding.GetEncoding("GB2312");
                for (int iRow = 1; iRow < dt.Rows.Count; iRow++)
                {
                    BaseInfoMember bifm = BaseInfoMember.New;
                    bifm.JoinedDate      = (DateTime)dt.Rows[iRow][0];
                    bifm.CardNumber      = dt.Rows[iRow][1].ToString();
                    bifm.MemberName      = dt.Rows[iRow][2].ToString();
                    bifm.PinYin          = PinYinTransfer.GetInitials(bifm.MemberName, gb2312);
                    bifm.Password        = dt.Rows[iRow][4].ToString();
                    bifm.Birth           = (DateTime)dt.Rows[iRow][5];
                    bifm.Mobile          = dt.Rows[iRow][6].ToString();
                    bifm.Phone           = dt.Rows[iRow][7].ToString();
                    bifm.DiscountRate    = decimal.Parse(dt.Rows[iRow][8].ToString());
                    bifm.RemainingSum    = decimal.Parse(dt.Rows[iRow][9].ToString());
                    bifm.TotalBonusPoint = decimal.Parse(dt.Rows[iRow][10].ToString());
                    bifm.Frequency       = decimal.Parse(dt.Rows[iRow][11].ToString());
                    bifm.TotalSpending   = decimal.Parse(dt.Rows[iRow][12].ToString());
                    bifm.Description     = dt.Rows[iRow][13].ToString();
                    bifm.SavedOn         = DateTime.Now;
                    bifm.OptrType        = UserStatics.OptrType;
                    bifm.Save();
                }
            }
        }
コード例 #3
0
        private void btnFullPay_Click(object sender, EventArgs e)
        {
            BaseInfoMember bim = BaseInfoMember.FindById(MemberId);

            if (ctCardNumber.Text == "" && ctMemberName.Text.Trim() != "")
            {
                MessageBox.Show("本单据看到会员名称,却看不到会员号,请确认会员号不能为空!");
            }
            else
            {
                //判断是否存在会员ID

                //1.如果会员ID不存在
                //1a.实收<应收,则提示实收款不足
                //2b.实收>=应收,则完成正常结算
                if (MemberId == 0)
                {
                    if (ctRealPay.Value < decimal.Parse(ctUnderPay.Text))
                    {
                        MessageBox.Show("实收不足以支付当前应收金额!");
                    }
                    else
                    {
                        PayAllDue();

                        //3.弹出支付完成提示窗口
                        //todo 需要初始化POS数据,增加单号
                        MessageBox.Show("已经完成结算!");
                    }
                }
                //2.会员ID存在
                //1a.会员存款>应收,直接扣除会员存款,完成结算
                //1b.会员存款<应收,
                //1ba.如果存款+实付 > 应收,完成结算,会员存款清零,并提示
                else
                {
                    if (decimal.Parse(ctRemainingSum.Text) >= decimal.Parse(ctUnderPay.Text))
                    {
                        PayAllDue();
                        bim.Frequency     += 1;
                        bim.RemainingSum  -= decimal.Parse(ctUnderPay.Text);
                        bim.TotalSpending += decimal.Parse(ctUnderPay.Text);
                        bim.Save();
                        MessageBox.Show("已经完成结算!");
                        InitialPos();
                    }
                    else
                    {
                        if (bim.RemainingSum + ctRealPay.Value >= decimal.Parse(ctUnderPay.Text))
                        {
                            PayAllDue();
                            bim.RemainingSum = 0;
                            bim.Save();
                            //todo 在这里提示会员是否充值
                            MessageBox.Show("会员余额已经为零,是否要充值?");
                        }
                        else
                        {
                            MessageBox.Show("会员余额不足以支付当前应收金额!");
                        }
                    }
                }
            }
        }