示例#1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            #region 检测

            if (ORDNO.Text.Trim().Length <= 0)
            {
                this.ShowWarningMessage("请输入工令号");
                return;
            }

            #endregion

            SqlConnection con = LocalGlobal.DbConnect();
            con.Open();
            SqlTransaction tran = con.BeginTransaction();//使用事务
            SqlCommand     cmd  = new SqlCommand();
            cmd.Connection  = con;
            cmd.Transaction = tran;

            string shipNo = LocalGlobal.NewSTNo(); //出货单号

            using (PurProvider purProvider = new PurProvider())
            {
                try
                {
                    int seq = 0;
                    foreach (GridViewRow row in List.Rows)
                    {
                        HtmlInputCheckBox rowCheckControl = (HtmlInputCheckBox)row.FindControl("RowCheck");
                        if (rowCheckControl.Checked)
                        {
                            seq++;

                            #region 检测

                            string noShipQty = row.Cells[6].Text.Trim();                            //未出货数量
                            string planQty   = ((TextBox)row.FindControl("shipqplan")).Text.Trim(); //计划出货数量
                            string shipDate  = ((TextBox)row.FindControl("shipdate")).Text.Trim();  //出货日期

                            if (shipDate.Length <= 0)
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("请填写出货日期!");
                                return;
                            }
                            if (Util.ToInt(planQty) <= 0)
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("出货数量必须大于0!");
                                return;
                            }
                            if (Util.ToInt(planQty) > Util.ToInt(noShipQty))
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("出货数量不能大于未出货数量!");
                                return;
                            }

                            string orNo   = List.DataKeys[row.RowIndex]["ordno"].ToString().Trim();
                            var    morder = purProvider.GetMOrder(orNo);
                            if (morder == null || morder.Rows.Count == 0)
                            {
                                var beiping = purProvider.GetBeiping(orNo);
                                if (beiping == null || beiping.Rows.Count == 0)
                                {
                                    tran.Rollback();
                                    this.ShowWarningMessage("任务的号码有误!");
                                    return;
                                }
                            }

                            #endregion

                            shipDate        = LocalGlobal.ConvertDateFormat(shipDate).ToString("yyyyMMdd");
                            cmd.CommandText = purProvider.InsertShipSql(shipNo, seq.ToString(), orNo, row.Cells[2].Text.Trim(), CustNo.Text.Trim(), CustName.Text.Trim(), row.Cells[3].Text.Trim(), row.Cells[5].Text.Trim(), row.Cells[4].Text.Trim(), planQty, "0", shipDate, "0");
                            cmd.ExecuteNonQuery();
                        }
                    }

                    if (seq <= 0)
                    {
                        this.ShowInfoMessage(this.GetGlobalResourceString("NotSelectMessage"));
                        tran.Rollback();
                        return;
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    this.ShowErrorMessage("保存失败。" + error.Message);
                    return;
                }

                tran.Commit();
                ShipNo.Text = shipNo;
                this.BindList();
            }
        }