Exemple #1
0
        /// <summary>
        /// 保存
        /// </summary>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            #region 检测

            int count = 0;
            foreach (GridViewRow row in PRList.Rows)
            {
                HtmlInputCheckBox rowCheckControl = (HtmlInputCheckBox)row.FindControl("RowCheck");
                if (rowCheckControl.Checked)
                {
                    count++;

                    string prDate = ((TextBox)row.FindControl("PRLPDTE")).Text.Trim();
                    if (LocalGlobal.ConvertDateFormat(prDate) <= DateTime.Today)
                    {
                        this.ShowInfoMessage("日期须在明天以后!");
                        return;
                    }
                }
            }

            if (count <= 0)
            {
                this.ShowInfoMessage(this.GetGlobalResourceString("NotSelectMessage"));
                return;
            }

            #endregion

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

            var    dateModel = LocalGlobal.GetDateModel();
            string prNo      = string.Empty;

            using (PurProvider purProvider = new PurProvider())
            {
                try
                {
                    if (PRNo.Text.Trim().Length == 0)               //新增
                    {
                        prNo = purProvider.GetMaxPRNo().ToString(); //生成新的请购单号
                        if (DRAWNO.Text.Trim().Length == 0)
                        {
                            DRAWNO.Text = " ";
                        }
                    }
                    else
                    {
                        //修改请购单
                        prNo = PRNo.Text.Trim();

                        //先删除再添加
                        cmd.CommandText = purProvider.DeletePRSql(prNo);
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = purProvider.DeletePRDetailSql(prNo);
                        cmd.ExecuteNonQuery();
                    }

                    #region Insert

                    cmd.CommandText = purProvider.InsertPRSql(prNo, ORDNO.Text.Trim(), DRAWNO.Text, "F", " ", "委外请购", LocalGlobal.CurrentUserID, dateModel.DateStr, LocalGlobal.CurrentUserID, dateModel.DateStr);
                    cmd.ExecuteNonQuery();

                    int seq = 0;
                    foreach (GridViewRow row in PRList.Rows)
                    {
                        HtmlInputCheckBox rowCheckControl    = (HtmlInputCheckBox)row.FindControl("RowCheck");
                        HtmlInputCheckBox urgentCheckControl = (HtmlInputCheckBox)row.FindControl("UrgentCheck");

                        if (rowCheckControl.Checked)
                        {
                            seq++;
                            string isUrgent   = urgentCheckControl.Checked ? "Y" : "N";
                            string prlstation = ((TextBox)row.FindControl("prlstation")).Text.Trim();
                            string prQty      = ((TextBox)row.FindControl("PRLQTY")).Text.Trim();
                            string prDate     = ((TextBox)row.FindControl("PRLPDTE")).Text.Trim();
                            prDate = LocalGlobal.ConvertDateFormat(prDate).ToString("yyyyMMdd");

                            cmd.CommandText = purProvider.InsertPRDetailSql(prNo, seq.ToString(), " ", prQty, prDate, prDate, "GT", ORDNO.Text.Trim(), "", row.Cells[3].Text.Trim(), prlstation, row.Cells[6].Text.Trim(), isUrgent, row.Cells[9].Text.Trim(), LocalGlobal.CurrentUserID, dateModel.DateStr, dateModel.TimeStr, "委外请购", row.Cells[7].Text.Trim());
                            cmd.ExecuteNonQuery();
                        }
                    }

                    #endregion

                    if (PRNo.Text.Trim().Length > 0)
                    {
                        //更新状态
                        cmd.CommandText = purProvider.UpdatePRStatusSql(prNo, "UP");
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    this.ShowErrorMessage("保存失败。" + error.Message);
                    return;
                }

                tran.Commit();

                PRNo.Text     = prNo;
                PRStatus.Text = LocalGlobal.GetPRStatus(prNo);
                this.BindList();
            }
        }
Exemple #2
0
        /// <summary>
        /// 保存
        /// </summary>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            var table = ViewState["ViewDT"] as DataTable;

            if (table == null || table.Rows.Count == 0)
            {
                return;
            }

            SqlConnection con = LocalGlobal.DbConnect();

            con.Open();
            SqlTransaction tran = con.BeginTransaction();//使用事务
            SqlCommand     cmd  = new SqlCommand();

            cmd.Connection  = con;
            cmd.Transaction = tran;

            var    dateModel = LocalGlobal.GetDateModel();
            string prNo      = string.Empty;

            using (PurProvider purProvider = new PurProvider())
            {
                try
                {
                    if (PRNo.Text.Trim().Length == 0)               //新增
                    {
                        prNo = purProvider.GetMaxPRNo().ToString(); //生成新的请购单号

                        cmd.CommandText = purProvider.InsertPRSql(prNo, "", "", "S", "RMB", "材料请购", LocalGlobal.CurrentUserID, dateModel.DateStr, "", "0");
                        cmd.ExecuteNonQuery();

                        PRStatus.Text = "NE";
                    }
                    else
                    {
                        //修改请购单
                        prNo = PRNo.Text.Trim();

                        //先删除再添加
                        cmd.CommandText = purProvider.DeletePRDetailSql(prNo);
                        cmd.ExecuteNonQuery();

                        //更新状态
                        cmd.CommandText = purProvider.UpdatePRStatusSql(prNo, "UP");
                        cmd.ExecuteNonQuery();

                        PRStatus.Text = "UP";
                    }

                    #region Insert

                    int seq = 0;
                    foreach (DataRow row in table.Rows)
                    {
                        seq++;

                        string prDate = row["PRLPDTE"].ToString().Trim();
                        prDate = LocalGlobal.ConvertDateFormat(prDate).ToString("yyyyMMdd");

                        cmd.CommandText = purProvider.InsertMatPRDetailSql(prNo, seq.ToString(), row["PRLQTY"].ToString().Trim(), prDate, prlwhs.Text.Trim(), row["prltno"].ToString(), row["prlstation"].ToString(), row["prlrule"].ToString(), row["prlum"].ToString(), LocalGlobal.CurrentUserID, dateModel.DateStr, dateModel.TimeStr, row["prlmrk"].ToString(), row["prloutno"].ToString(), row["prlpicno"].ToString());

                        cmd.ExecuteNonQuery();
                    }

                    #endregion
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    this.ShowErrorMessage("保存失败。" + error.Message);
                    return;
                }

                tran.Commit();

                PRNo.Text = prNo;
                this.BindList();
            }
        }