Пример #1
0
        public List <RefundDetail> QueryDetail(int?orderID)
        {
            List <RefundDetail> result = new List <RefundDetail>();
            string command             = string.Empty;

            command = "select RefundAmount,RefundResoin,code from RefundDetail where orderId ='" + orderID + "'";
            DataTable dt = conn.GetDataTableBySql(command);

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    RefundDetail entry = new RefundDetail();
                    entry.RefundAmount = decimal.Parse(dt.Rows[i][0].ToString());
                    entry.RefundResoin = dt.Rows[i][1].ToString();
                    entry.code         = dt.Rows[i][2].ToString();
                    result.Add(entry);
                }
            }
            return(result);
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //SqlConnection localhost = new SqlConnection("data source=192.168.1.11;initial catalog=OrderManage;persist security info=False;user id=sa;password=sa;");
            SqlConnection       localhost        = new SqlConnection("data source=localhost;initial catalog=OrderManage;persist security info=False;user id=sa;password=sa;");
            List <OrderEntry>   resultList       = new List <OrderEntry>();
            List <RefundDetail> resultDetailList = new List <RefundDetail>();
            List <User>         UserList         = new List <User>();
            string command = string.Empty;

            command = "select * from OrderRecord Order by ID";
            DataTable dt = this.GetDataTableBySql(command, localhost);

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    OrderEntry entry = new OrderEntry();
                    //entry.SeqNum = seq;
                    entry.ID           = int.Parse(dt.Rows[i]["ID"].ToString());
                    entry.Status       = dt.Rows[i]["Status"].ToString();
                    entry.ShopName     = dt.Rows[i]["ShopName"].ToString();
                    entry.BuyersID     = dt.Rows[i]["BuyersID"].ToString();
                    entry.RefundWay    = dt.Rows[i]["RefundWay"].ToString();
                    entry.AlipayNo     = dt.Rows[i]["AlipayNo"].ToString();
                    entry.RefundAmount = decimal.Parse(dt.Rows[i]["RefundAmount"].ToString());
                    entry.RefundResoin = dt.Rows[i]["RefundResoin"].ToString();
                    entry.Remark       = dt.Rows[i]["Remark"].ToString();
                    entry.CreateUser   = dt.Rows[i]["CreateUser"].ToString();
                    if (!string.IsNullOrEmpty(dt.Rows[i]["RefundTime"].ToString()))
                    {
                        entry.RefundTime = DateTime.Parse(dt.Rows[i]["RefundTime"].ToString());
                    }

                    entry.RefundUserName = dt.Rows[i]["RefundUserName"].ToString();
                    if (dt.Rows[i]["IsDelete"].ToString() == "1")
                    {
                        entry.IsDelete = true;
                    }
                    else
                    {
                        entry.IsDelete = false;
                    }
                    if (!string.IsNullOrEmpty(dt.Rows[i]["CreateTime"].ToString()))
                    {
                        entry.CreateTime = DateTime.Parse(dt.Rows[i]["CreateTime"].ToString());
                    }
                    entry.PDName1 = dt.Rows[i]["PDName1"].ToString();
                    entry.PDName2 = dt.Rows[i]["PDName2"].ToString();
                    entry.PDName3 = dt.Rows[i]["PDName3"].ToString();
                    entry.PDName4 = dt.Rows[i]["PDName4"].ToString();
                    entry.PDName5 = dt.Rows[i]["PDName5"].ToString();
                    if (!string.IsNullOrEmpty(dt.Rows[i]["No"].ToString()))
                    {
                        entry.No = int.Parse(dt.Rows[i]["No"].ToString());
                    }
                    else
                    {
                        entry.No = null;
                    }
                    entry.ExpressNo2     = dt.Rows[i]["ExpressNo2"].ToString();
                    entry.ExpressNo3     = dt.Rows[i]["ExpressNo3"].ToString();
                    entry.RefundAlipayNo = dt.Rows[i]["RefundAlipayNo"].ToString();
                    //seq++;
                    resultList.Add(entry);
                }
            }
            command = "select * from RefundDetail Order by ID";
            dt      = this.GetDataTableBySql(command, localhost);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    RefundDetail entry = new RefundDetail();
                    //entry.SeqNum = seq;
                    entry.ID           = int.Parse(dt.Rows[i]["ID"].ToString());
                    entry.orderId      = int.Parse(dt.Rows[i]["orderId"].ToString());
                    entry.RefundAmount = decimal.Parse(dt.Rows[i]["RefundAmount"].ToString());
                    entry.RefundResoin = dt.Rows[i]["RefundResoin"].ToString();
                    entry.code         = dt.Rows[i]["code"].ToString();
                    resultDetailList.Add(entry);
                }
            }
            command = "select * from \"User\" Order by ID";
            dt      = this.GetDataTableBySql(command, localhost);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    User entry = new User();
                    //entry.SeqNum = seq;
                    entry.ID       = int.Parse(dt.Rows[i]["ID"].ToString());
                    entry.UserName = dt.Rows[i]["UserName"].ToString();
                    entry.Password = dt.Rows[i]["Password"].ToString();
                    entry.Name     = dt.Rows[i]["Name"].ToString();

                    UserList.Add(entry);
                }
            }
            this.tbCount.Text = (resultList.Count() + resultDetailList.Count() + UserList.Count()).ToString();
            int insertCount = 0;

            foreach (var user in UserList)
            {
                command  = "set IDENTITY_INSERT \"User\" ON ;";
                command += "insert into \"User\"(\"ID\",\"UserName\",\"Password\",\"Name\") values('" + user.ID + "','" + user.UserName + "','" + user.Password + "','" + user.Name + "')";
                command += " set IDENTITY_INSERT \"User\" off;";
                string message = conn.ExecuteSql(command);
                insertCount++;
                this.tbInsert.Text = insertCount.ToString();
                System.Windows.Forms.Application.DoEvents();
            }
            foreach (var detail in resultDetailList)
            {
                command  = "set IDENTITY_INSERT RefundDetail ON ;";
                command += "insert into \"RefundDetail\"(\"ID\",\"orderId\",\"RefundAmount\",\"RefundResoin\",\"code\") values('" + detail.ID + "','" + detail.orderId + "','" + detail.RefundAmount + "','" + detail.RefundResoin + "','" + detail.code + "')";
                command += " set IDENTITY_INSERT RefundDetail off;";
                string message = conn.ExecuteSql(command);
                insertCount++;
                this.tbInsert.Text = insertCount.ToString();
                System.Windows.Forms.Application.DoEvents();
            }
            foreach (var result in resultList)
            {
                //\"RefundTime\"='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'
                string isDelete = string.Empty;
                if (result.IsDelete == true)
                {
                    isDelete = "True";
                }
                else
                {
                    isDelete = "False";
                }
                string refundTime = string.Empty;
                string createTime = string.Empty;
                if (result.RefundTime.HasValue)
                {
                    refundTime = result.RefundTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                if (result.CreateTime.HasValue)
                {
                    createTime = result.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                command  = "set IDENTITY_INSERT OrderRecord ON ;";
                command += " insert into \"OrderRecord\"(\"id\",\"Status\",\"ShopName\",\"BuyersID\",\"RefundWay\",\"AlipayNo\",\"RefundAmount\",\"RefundResoin\",\"Remark\",\"CreateUser\",\"IsDelete\",\"PDName1\",\"PDName2\",\"PDName3\",\"PDName4\",\"PDName5\",\"ExpressNo2\",\"ExpressNo3\",\"CreateTime\",\"RefundTime\",\"RefundUserName\",\"No\",\"RefundAlipayNo\") Values(" + result.ID + ",'" + result.Status + "','" + result.ShopName + "','" + result.BuyersID + "','" + result.RefundWay + "','" + result.AlipayNo + "','" + result.RefundAmount + "','" + result.RefundResoin + "','" + result.Remark + "','" + result.CreateUser + "','" + isDelete + "','" + result.PDName1 + "','" + result.PDName2 + "','" + result.PDName3 + "','" + result.PDName4 + "','" + result.PDName5 + "','" + result.ExpressNo2 + "','" + result.ExpressNo3 + "','" + createTime + "','" + refundTime + "','" + result.RefundUserName + "','" + result.No + "','" + result.RefundAlipayNo + "') ;";
                command += " set IDENTITY_INSERT OrderRecord off;";
                string message = conn.ExecuteSql(command);
                insertCount++;
                this.tbInsert.Text = insertCount.ToString();
                System.Windows.Forms.Application.DoEvents();
            }
        }
Пример #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string command = string.Empty;

            if (isShowTip == false)
            {
                if (!string.IsNullOrWhiteSpace(this.tbBuyerID.Text))
                {
                    command = string.Empty;
                    command = "select * from \"OrderRecord\" where \"BuyersID\" like '%" + this.tbBuyerID.Text.Trim() + "%' and \"IsDelete\"='False' order by convert(datetime,CreateTime) desc";
                    DataTable dt = conn.GetDataTableBySql(command);
                    if (dt.Rows.Count > 0)
                    {
                        DateTime createTime = DateTime.Parse(dt.Rows[0]["CreateTime"].ToString());
                        var      time       = DateTime.Now - createTime;
                        if (time.TotalDays <= 30)
                        {
                            if (MessageBox.Show("    买家ID已存在退款记录,请核对!是否继续保存?", "提醒", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                            }
                            else
                            {
                                return;
                            }
                            //if(MessageBox.Show("买家ID已存在退款记录,请核对!", "提示"));
                            //return;
                        }
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(this.cmbShopName.Text))
            {
                MessageBox.Show("请输入店铺名称!");
                return;
            }
            if (string.IsNullOrWhiteSpace(this.tbBuyerID.Text))
            {
                MessageBox.Show("请输入买家ID!");
                return;
            }
            if (string.IsNullOrWhiteSpace(this.cmbRefundWay.Text))
            {
                MessageBox.Show("请输入退款方式!");
                return;
            }
            if (this.cmbRefundWay.Text == "支付宝")
            {
                if (string.IsNullOrWhiteSpace(this.tbAlipayNo.Text))
                {
                    MessageBox.Show("请输入支付宝帐号!");
                    return;
                }
                else if (this.tbAlipayNo.Text.Length < 5)
                {
                    MessageBox.Show("支付宝账号应大于5个字符");
                    return;
                }
            }



            int id = 0;

            command = "select max(id) from OrderRecord ";
            DataTable dt1 = conn.GetDataTableBySql(command);

            if (dt1.Rows.Count > 0)
            {
                id = int.Parse(dt1.Rows[0][0].ToString());
            }
            id++;

            string  refundResion = string.Empty;
            decimal amount1      = 0;
            decimal refundAmount = 0;

            detailList = new List <RefundDetail>();
            RefundDetail entry = new RefundDetail();

            entry.orderId = id;
            if (!string.IsNullOrWhiteSpace(this.tbRefundAmount.Text))
            {
                entry.RefundAmount = decimal.Parse(this.tbRefundAmount.Text);
            }
            entry.RefundResoin = this.cmbRefundResoin.Text;
            entry.code         = this.txtCode.Text;
            detailList.Add(entry);
            refundAmount += entry.RefundAmount;
            refundResion  = entry.RefundResoin + "     " + entry.RefundAmount + "     " + entry.code + Environment.NewLine;

            #region 退款原因赋值
            if (!string.IsNullOrWhiteSpace(this.tbCode1.Text) || !string.IsNullOrWhiteSpace(this.tbRefundAmount1.Text) || !string.IsNullOrWhiteSpace(this.cmbRefundResoin1.Text))
            {
                RefundDetail entry1 = new RefundDetail();
                entry1.orderId = id;
                if (!string.IsNullOrWhiteSpace(this.tbRefundAmount1.Text))
                {
                    entry1.RefundAmount = decimal.Parse(this.tbRefundAmount1.Text);
                }
                amount1             = entry1.RefundAmount;
                entry1.RefundResoin = this.cmbRefundResoin1.Text;
                entry1.code         = this.tbCode1.Text;
                refundAmount       += entry1.RefundAmount;
                refundResion       += entry1.RefundResoin + "     " + amount1 + "     " + entry1.code + Environment.NewLine;
                detailList.Add(entry1);
            }
            if (!string.IsNullOrWhiteSpace(this.tbCode2.Text) || !string.IsNullOrWhiteSpace(this.tbRefundAmount2.Text) || !string.IsNullOrWhiteSpace(this.cmbRefundResoin2.Text))
            {
                RefundDetail entry1 = new RefundDetail();
                entry1.orderId = id;
                if (!string.IsNullOrWhiteSpace(this.tbRefundAmount2.Text))
                {
                    entry1.RefundAmount = decimal.Parse(this.tbRefundAmount2.Text);
                }
                amount1             = entry1.RefundAmount;
                entry1.RefundResoin = this.cmbRefundResoin2.Text;
                entry1.code         = this.tbCode2.Text;
                refundAmount       += entry1.RefundAmount;
                refundResion       += entry1.RefundResoin + "     " + amount1 + "     " + entry1.code + Environment.NewLine;
                detailList.Add(entry1);
            }
            if (!string.IsNullOrWhiteSpace(this.tbCode3.Text) || !string.IsNullOrWhiteSpace(this.tbRefundAmount3.Text) || !string.IsNullOrWhiteSpace(this.cmbRefundResoin3.Text))
            {
                RefundDetail entry1 = new RefundDetail();
                entry1.orderId = id;
                if (!string.IsNullOrWhiteSpace(this.tbRefundAmount3.Text))
                {
                    entry1.RefundAmount = decimal.Parse(this.tbRefundAmount3.Text);
                }
                amount1             = entry1.RefundAmount;
                entry1.RefundResoin = this.cmbRefundResoin3.Text;
                entry1.code         = this.tbCode3.Text;
                refundAmount       += entry1.RefundAmount;
                refundResion       += entry1.RefundResoin + "     " + amount1 + "     " + entry1.code + Environment.NewLine;
                detailList.Add(entry1);
            }
            if (!string.IsNullOrWhiteSpace(this.tbCode4.Text) || !string.IsNullOrWhiteSpace(this.tbRefundAmount4.Text) || !string.IsNullOrWhiteSpace(this.cmbRefundResoin4.Text))
            {
                RefundDetail entry1 = new RefundDetail();
                entry1.orderId = id;
                if (!string.IsNullOrWhiteSpace(this.tbRefundAmount4.Text))
                {
                    entry1.RefundAmount = decimal.Parse(this.tbRefundAmount4.Text);
                }
                amount1             = entry1.RefundAmount;
                entry1.RefundResoin = this.cmbRefundResoin4.Text;
                entry1.code         = this.tbCode4.Text;
                refundAmount       += entry1.RefundAmount;
                refundResion       += entry1.RefundResoin + "     " + amount1 + "     " + entry1.code + Environment.NewLine;
                detailList.Add(entry1);
            }
            if (!string.IsNullOrWhiteSpace(this.tbCode5.Text) || !string.IsNullOrWhiteSpace(this.tbRefundAmount5.Text) || !string.IsNullOrWhiteSpace(this.cmbRefundResoin5.Text))
            {
                RefundDetail entry1 = new RefundDetail();
                entry1.orderId = id;
                if (!string.IsNullOrWhiteSpace(this.tbRefundAmount5.Text))
                {
                    entry1.RefundAmount = decimal.Parse(this.tbRefundAmount5.Text);
                }
                amount1             = entry1.RefundAmount;
                entry1.RefundResoin = this.cmbRefundResoin5.Text;
                entry1.code         = this.tbCode5.Text;
                refundAmount       += entry1.RefundAmount;
                refundResion       += entry1.RefundResoin + "     " + amount1 + "     " + entry1.code + Environment.NewLine;
                detailList.Add(entry1);
            }
            #endregion
            //if (this.dataGridView1.Rows.Count > 0)
            //{
            //    foreach (var item in this.dataGridView1.Rows)
            //    {
            //        var gridRow = item as DataGridViewRow;
            //        //var row = gridRow.DataBoundItem as RefundDetail;
            //        if (gridRow.Cells[0].Value != null)
            //        {
            //            if (!string.IsNullOrWhiteSpace(gridRow.Cells[0].Value.ToString()))
            //                amount1 = decimal.Parse(gridRow.Cells[0].Value.ToString());
            //            refundAmount += amount1;
            //            refundResion += gridRow.Cells[2].Value + "     " + amount1 + "     " + gridRow.Cells[1].Value + Environment.NewLine;
            //            RefundDetail entry1 = new RefundDetail();
            //            entry1.orderId = id;
            //            entry1.RefundAmount = amount1;
            //            if (gridRow.Cells[2].Value!=null)
            //            entry1.RefundResoin = gridRow.Cells[2].Value.ToString();
            //            if (gridRow.Cells[1].Value != null)
            //                entry1.code = gridRow.Cells[1].Value.ToString();
            //            detailList.Add(entry1);
            //        }
            //    }

            //}
            //else
            //{
            //    refundAmount = decimal.Parse(this.tbRefundAmount.Text);
            //    refundResion = this.cmbRefundResoin.Text;
            //}
            if (string.IsNullOrWhiteSpace(this.tbRefundAmount.Text) && detailList.Where(v => v.RefundAmount > 0).Count() == 0 && this.cmbRefundWay.Text != "补发")
            {
                MessageBox.Show("请输入退款金额!");
                return;
            }
            if (string.IsNullOrWhiteSpace(this.cmbRefundResoin.Text) && detailList.Where(v => !string.IsNullOrWhiteSpace(v.RefundResoin)).Count() == 0)
            {
                MessageBox.Show("请输入退款原因!");
                return;
            }
            //decimal amount = decimal.Parse(decimal.Parse(this.tbRefundAmount.Text).ToString("F2"));
            decimal amount = 0;
            amount = decimal.Parse(refundAmount.ToString("F2"));
            string status = string.Empty;
            if ((this.cmbRefundWay.Text == "支付宝" && amount >= 15) || (this.cmbRefundResoin.Text == "漏发" && amount > 10))
            {
                status = "待审核";
            }
            else
            {
                status = "未处理";
            }

            //处理录入次数
            int inputCount = this.QueryInputCount(this.tbBuyerID.Text);

            command  = "set IDENTITY_INSERT OrderRecord ON ;";
            command += " insert into \"OrderRecord\"(\"id\",\"Status\",\"ShopName\",\"BuyersID\",\"RefundWay\",\"AlipayNo\",\"RefundAmount\",\"RefundResoin\",\"Remark\",\"CreateUser\",\"IsDelete\",\"PDName1\",\"PDName2\",\"PDName3\",\"PDName4\",\"PDName5\",\"ExpressNo2\",\"ExpressNo3\",InputCount) Values(" + id + ",'" + status + "','" + this.cmbShopName.Text + "','" + this.tbBuyerID.Text + "','" + this.cmbRefundWay.Text + "','" + this.tbAlipayNo.Text + "','" + amount + "','" + refundResion + "','" + this.tbRemark.Text + "','" + this.tbCreateUser.Text + "','false','" + this.tbPdName1.Text + "','" + this.tbPdName2.Text + "','" + this.tbPdName3.Text + "','" + this.tbPdName4.Text + "','" + this.tbExpressNo1.Text + "','" + this.tbExpressNo2.Text + "','" + this.tbExpressNo3.Text + "'," + inputCount + ") ;";
            command += "set IDENTITY_INSERT OrderRecord off;";
            string message = conn.ExecuteSql(command);
            if (!string.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show("保存失败!失败原因:" + message);
            }
            else
            {
                MessageBox.Show("录入成功");
                if (detailList.Count() > 0)
                {
                    foreach (var item in detailList)
                    {
                        command = "insert into RefundDetail(orderId,RefundAmount,RefundResoin,code) values('" + item.orderId + "','" + item.RefundAmount + "','" + item.RefundResoin + "','" + item.code + "')";
                        message = conn.ExecuteSql(command);
                    }
                }

                //this.dataGridView1.DataSource = null;
                //foreach (var item in this.dataGridView1.Rows)
                //{
                //    var gridRow = item as DataGridViewRow;
                //    this.dataGridView1.Rows.Remove(gridRow);
                //}
                this.tbBuyerID.Text      = "";
                this.tbAlipayNo.Text     = "";
                this.tbRefundAmount.Text = "";
                //this.cmbRefundWay.Text = "";
                this.cmbRefundResoin.Text = "";
                this.tbCreateUser.Text    = UserEntry.Name;
                this.tbRemark.Text        = "";
                this.tbPdName1.Text       = "";
                this.tbPdName2.Text       = "";
                this.tbPdName3.Text       = "";
                this.tbPdName4.Text       = "";
                this.tbExpressNo1.Text    = "";
                this.tbExpressNo2.Text    = "";
                this.tbExpressNo3.Text    = "";
                this.tbUp.Text            = "";

                this.tbCode1.Text                   = "";
                this.tbCode2.Text                   = "";
                this.tbCode3.Text                   = "";
                this.tbCode4.Text                   = "";
                this.tbCode5.Text                   = "";
                this.tbRefundAmount1.Text           = "";
                this.tbRefundAmount2.Text           = "";
                this.tbRefundAmount3.Text           = "";
                this.tbRefundAmount4.Text           = "";
                this.tbRefundAmount5.Text           = "";
                this.cmbRefundResoin1.SelectedIndex = 0;
                this.cmbRefundResoin2.SelectedIndex = 0;
                this.cmbRefundResoin3.SelectedIndex = 0;
                this.cmbRefundResoin4.SelectedIndex = 0;
                this.cmbRefundResoin5.SelectedIndex = 0;
                //this.dataGridView1.DataSource = null;
                //while (this.dataGridView1.Rows.Count > 0)
                //{
                //    this.dataGridView1.Rows.RemoveAt(0);
                //}
                ////this.dataGridView1.i
                //this.dataGridView1.Rows.Add();
                //this.dataGridView1.Rows.Add();
                //this.dataGridView1.Rows.Add();
                //this.dataGridView1.Rows.Add();
                //this.dataGridView1.Rows.Add();
                //Input input = new Input(shopNameList, refundWay);
                //this.Hide();
                //input.Show();
                //this.Hide();
            }
        }