Beispiel #1
0
    /// <summary>
    /// 複製鈕(複製視窗內的)
    /// </summary>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region 輸入檢查

        if (SLP_CopyFromDate.Text == "")
        {
            ErrorMsgLabel.Text = "舊[門市進貨日]欄位不得空白";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 舊[門市進貨日]欄位不得空白 ');", true);
            return;
        }

        if (txtPickBatchCopyFrom.Text == "")
        {
            ErrorMsgLabel.Text = "舊[理貨批次]欄位不得空白";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 舊[理貨批次]欄位不得空白 ');", true);
            return;
        }

        if (SLP_CopyToDate.Text == "")
        {
            ErrorMsgLabel.Text = "新[門市進貨日]欄位不得空白";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[門市進貨日]欄位不得空白 ');", true);
            return;
        }

        if (Convert.ToDateTime(SLP_CopyToDate.Text) <= DateTime.Now)
        {
            ErrorMsgLabel.Text = "新[門市進貨日]欄位不得小於等於系統日";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[門市進貨日]欄位不得小於等於系統日 ');", true);
            return;
        }

        if (txtPickBatchCopyTo.Text == "")
        {
            ErrorMsgLabel.Text = "新[理貨批次]欄位不得空白";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[理貨批次]欄位不得空白 ');", true);
            return;
        }

        #endregion

        System.IO.TextReader tr;

        CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon();
        System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction();

        try
        {
            CGDModel.MaintainSetRouteOrder BCO = new CGDModel.MaintainSetRouteOrder(ConntionDB);
            string strWhere = "";

            // 檢查新日期是否有資料-----------------------------------------------------------------------------------------
            #region  checking


            DataTable DtCheckNew;
            ParameterList.Clear();

            ParameterList.Add(this.SLP_CopyToDate.Text.Trim());
            ParameterList.Add(this.txtPickBatchCopyTo.Text.Trim());

            DtCheckNew = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.QueryRouteOrder, ParameterList);

            if (DtCheckNew.Rows.Count > 0)
            {
                ErrorMsgLabel.Text = "輸入的新門市進貨日已有資料";

                //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 輸入的新門市進貨日已有資料 ');", true);
                return;
            }


            #endregion

            // 檢查舊日期是否有資料 , 如有資料則進行複製--------------------------------------------------------------------
            #region  checking


            DataTable DtCheckOld;
            ParameterList.Clear();

            ParameterList.Add(this.SLP_CopyFromDate.Text.Trim());
            ParameterList.Add(this.txtPickBatchCopyFrom.Text.Trim());

            DtCheckOld = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.QueryRouteOrder, ParameterList);

            if (DtCheckOld.Rows.Count == 0)
            {
                ErrorMsgLabel.Text = "輸入的舊門市進貨日沒有資料可以複製";

                //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 輸入的舊門市進貨日沒有資料可以複製 ');", true);
                return;
            }
            else
            {
                for (int i = 0; i <= DtCheckOld.Rows.Count - 1; i++)
                {
                    ParameterList.Clear();
                    ParameterListDel.Clear();

                    ParameterList.Add(DtCheckOld.Rows[i]["NAME"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["CREATEDATE"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["CREATEUID"]);
                    ParameterList.Add(System.DateTime.Now);
                    ParameterList.Add(Session["UID"].ToString());
                    ParameterList.Add(DtCheckOld.Rows[i]["STATUS"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["ENABLE"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["DPS_CODE"]);
                    ParameterList.Add(Convert.ToDateTime(this.SLP_CopyToDate.Text.Trim()));
                    ParameterList.Add(this.txtPickBatchCopyTo.Text.Trim());
                    ParameterList.Add(DtCheckOld.Rows[i]["LINE"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["PICK_ORDER"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["ROUTE"]);
                    ParameterList.Add(DtCheckOld.Rows[i]["STORE_CNT"]);

                    BCO.InsertRouteOrder(ParameterList, DBT);
                }
                DBT.Commit();//交易成功
            }


            #endregion

            ErrorMsgLabel.Text = "複製完畢";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 複製完畢 ');", true);
        }
        catch (Exception ex)
        {
            DBT.Rollback();//交易失敗

            ErrorMsgLabel.Text = ex.Message;
        }

        btnCloseCopy_Click(null, null);
    }
Beispiel #2
0
    /// <summary>
    /// 儲存鈕
    /// </summary>
    protected void btnSave_Click1(object sender, EventArgs e)
    {
        string SessionIDName = "CGD011_" + PageTimeStamp.Value;

        DataTable Dt = null;

        DataTable DT_Add = null;
        DataTable DT_Mod = null;
        DataTable DT_Del = null;

        if (Session[SessionIDName] != null)
        {
            Dt = (DataTable)Session[SessionIDName];

            DT_Add = Dt.GetChanges(DataRowState.Added);
            DT_Mod = Dt.GetChanges(DataRowState.Modified);
            DT_Del = Dt.GetChanges(DataRowState.Deleted);
        }
        else
        {
            ErrorMsgLabel.Text = "目前無資料異動";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 目前無資料異動 ');", true);
            return;
        }

        if (DT_Add == null && DT_Mod == null && DT_Del == null)
        {
            ErrorMsgLabel.Text = "目前無資料異動";

            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 目前無資料異動 ');", true);
            return;
        }

        CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon();
        System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction();
        CGDModel.MaintainSetRouteOrder BCO = new CGDModel.MaintainSetRouteOrder(ConntionDB);



        try
        {
            //刪除----------------------------------------------------------------------------------------------------------
            if (DT_Del != null)
            {
                foreach (DataRow dRow in DT_Del.Rows)
                {
                    ParameterList.Clear();

                    ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Original].ToString());
                    ParameterList.Add(Convert.ToDateTime(dRow["ST_ACCEPT_DATE", DataRowVersion.Original].ToString()).ToShortDateString());
                    ParameterList.Add(dRow["ROUTE", DataRowVersion.Original].ToString());
                    ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original].ToString()));
                    ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Original].ToString());

                    string MSG = BCO.DeleteRouteOrder(ParameterList, DBT);

                    if (MSG == "NODATA")
                    {
                        throw new Exception("DB_NODATA");
                    }
                }
            }

            //新增----------------------------------------------------------------------------------------------------------
            if (DT_Add != null)
            {
                foreach (DataRow dRow in DT_Add.Rows)
                {
                    ParameterList.Clear();

                    if (DT_Add.Columns.Contains("NAME").ToString() == "True")
                    {
                        ParameterList.Add(dRow["NAME"]);
                    }
                    else
                    {
                        ParameterList.Add(dRow["LINE"].ToString() + "-" + dRow["ROUTE"].ToString());
                    }
                    ParameterList.Add(dRow["CREATEDATE"]);
                    ParameterList.Add(dRow["CREATEUID"]);
                    ParameterList.Add(dRow["UPDATEDATE"]);
                    ParameterList.Add(dRow["UPDATEUID"]);
                    if (DT_Add.Columns.Contains("STATUS").ToString() == "True")
                    {
                        ParameterList.Add(dRow["STATUS"]);
                    }
                    else
                    {
                        ParameterList.Add(0);
                    }
                    ParameterList.Add(dRow["ENABLE"]);
                    ParameterList.Add(dRow["DPS_CODE"]);
                    ParameterList.Add(Convert.ToDateTime(dRow["ST_ACCEPT_DATE"]).ToShortDateString());
                    ParameterList.Add(dRow["PICK_BATCH"]);
                    ParameterList.Add(dRow["LINE"]);
                    ParameterList.Add(dRow["PICK_ORDER"]);
                    ParameterList.Add(dRow["ROUTE"]);
                    ParameterList.Add(dRow["STORE_CNT"]);


                    BCO.InsertRouteOrder(ParameterList, DBT);
                }
            }

            //修改----------------------------------------------------------------------------------------------------------
            if (DT_Mod != null)
            {
                foreach (DataRow dRow in DT_Mod.Rows)
                {
                    ParameterList.Clear();

                    ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["NAME", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["DPS_CODE", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["ST_ACCEPT_DATE", DataRowVersion.Current]);
                    ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["LINE", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["PICK_ORDER", DataRowVersion.Current].ToString());
                    ParameterList.Add(dRow["ROUTE", DataRowVersion.Current].ToString());
                    ParameterList.Add(Convert.ToInt32(dRow["STORE_CNT", DataRowVersion.Current].ToString()));

                    ParameterList.Add(Convert.ToDateTime(dRow["CREATEDATE", DataRowVersion.Original].ToString()));
                    ParameterList.Add(dRow["CREATEUID", DataRowVersion.Original].ToString());
                    ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original].ToString()));
                    ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Original].ToString());
                    ParameterList.Add(Convert.ToInt16(dRow["STATUS", DataRowVersion.Original].ToString()));
                    ParameterList.Add(Convert.ToInt16(dRow["ENABLE", DataRowVersion.Original].ToString()));
                    ParameterList.Add(dRow["NAME", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["DPS_CODE", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["ST_ACCEPT_DATE", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["LINE", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["PICK_ORDER", DataRowVersion.Original].ToString());
                    ParameterList.Add(dRow["ROUTE", DataRowVersion.Original].ToString());
                    ParameterList.Add(Convert.ToInt32(dRow["STORE_CNT", DataRowVersion.Original].ToString()));

                    string MSG = BCO.UpdateRouteOrder(ParameterList, DBT);

                    if (MSG == "NODATA")
                    {
                        throw new Exception("DB_NODATA");
                    }
                }
            }

            DBT.Commit();//交易成功

            btnQuery_Click(null, null);

            ErrorMsgLabel.Text = "儲存完畢";
            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 儲存完畢 ');", true);
        }
        catch (Exception ex)
        {
            DBT.Rollback();//交易失敗

            if (ex.Message.IndexOf("違反必須為唯一的限制條件") > 0)
            {
                ErrorMsgLabel.Text = "新增之站所已重複";

                //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 新增之站所已重複 ');", true);
                return;
            }

            if (ex.Message.IndexOf("NODATA") > 0)
            {
                ErrorMsgLabel.Text = "原資料已異動過,請重新查詢資料後再作處理";

                //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 原資料已異動過,請重新查詢資料後再作處理 ');", true);
                return;
            }

            ErrorMsgLabel.Text = ex.Message;
        }
        finally { }
    }