Example #1
0
    protected void btnModify_Click(object sender, EventArgs e)
    {
        switch (OperationMode)
        {
            case OpMode.View:
                try
                {
                    OperationMode = OpMode.Edit;
                    SLP_VENDOR.ReadOnly = true;
                    DDL_PAY_KIND.Enabled = true;
                    DDL_TRAN_CORP.Enabled = true;
                    GridView1.Columns[2].Visible = true;
                    
                    if (CanCreate == true)
                    {
                        btnAddTranItem.Visible = true;
                    }
                    else
                    {
                        btnAddTranItem.Visible = false;
                    }


                    GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Save, true, "", btnModify,
                    WUI_GMToolbarV.ClickAction.ButtonClick);
                    GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Edit, false, "", null,
                    WUI_GMToolbarV.ClickAction.ButtonClick);
                    GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Copy, false, "", null,
                    WUI_GMToolbarV.ClickAction.ButtonClick);
                }
                catch (Exception ex)
                {
                    WaringLogProcess(ex.Message);
                    this.ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0];  //直接取第一個
                }
                finally { Finally_Function(); }

                break;

            case OpMode.Edit:
                try
                {
                    if (string.IsNullOrEmpty(SLP_VENDOR.Text.Trim()) || string.IsNullOrEmpty(DDL_PAY_KIND.SelectedValue)
                        || string.IsNullOrEmpty(DDL_TRAN_CORP.SelectedValue))
                    {
                        ErrorMsgLabel.Text = "供應商代號、商品收費方式、轉運商運費 需有值";
                        return;
                    }

                    DataTable dt = ItemData.GetChanges(DataRowState.Deleted);
                    int inCount = (dt == null ? 0 : dt.Rows.Count);
                    if ((DDL_PAY_KIND.SelectedValue == "1" || DDL_PAY_KIND.SelectedValue == "2"))
                    {
                        if (ItemData.Rows.Count > 0)
                        {
                            if (inCount != ItemData.Rows.Count)
                            {
                                ErrorMsgLabel.Text = "商品收費方式若為【全部要收】或【全部不收】,則不需設定明細資料,請先將所有品項刪除";
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (ItemData.Rows.Count > 0)
                        {
                            if (inCount == ItemData.Rows.Count)
                            {
                                ErrorMsgLabel.Text = "商品收費方式如為單品要收或單品不收,就需設定明細資料";
                                return;
                            }
                        }
                        else
                        {
                            ErrorMsgLabel.Text = "商品收費方式如為單品要收或單品不收,就需設定明細資料";
                            return;
                        }
                    }

                    //把修改寫回資料庫
                    ArrayList parameterList = new ArrayList();
                    ArrayList parameterList2 = new ArrayList();
                    VAM24_BCO bco = new VAM24_BCO(ConnectionDB);
                    CAMCommon bco1 = new CAMCommon();

                    try
                    {
                        parameterList.Add(bco1.GetValueSetParameter(ViewState["CurrentID"].ToString(), "string", false)); //0
                        parameterList.Add(bco1.GetValueSetParameter(DDL_PAY_KIND.SelectedValue, "string", false));        //1
                        parameterList.Add(bco1.GetValueSetParameter(DDL_TRAN_CORP.SelectedValue, "string", false));       //2
                        parameterList.Add(bco1.GetValueSetParameter(Session["UID"].ToString(), "string", false));         //3

                        for (int i = 0; i < ItemData.Rows.Count; i++)
                        {
                            if (ItemData.Rows[i].RowState != DataRowState.Deleted)
                            {
                                ArrayList detailParameter = new ArrayList();
                                detailParameter.Add(bco1.GetValueSetParameter(ItemData.Rows[i]["ITEM"].ToString(), "string", false));
                                detailParameter.Add(bco1.GetValueSetParameter(Session["UID"].ToString(), "string", false));
                                parameterList2.Add(detailParameter);
                            }
                        }

                        string strReturn = bco.UpdateTranShip(parameterList, parameterList2);

                        if (strReturn != "")
                        {
                            this.ErrorMsgLabel.Text = "更新失敗:" + strReturn;
                            return;
                        }

                        OperationMode = OpMode.View;

                        SetControlStatus();
                        BindData();
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Save, false, "", null,
                        WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Edit, true, "", btnModify,
                        WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Copy, false, string.Empty, null, WUI_GMToolbarV.ClickAction.ButtonClick);
                        this.ErrorMsgLabel.Text = "更新成功";

                        ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", string.Format("alert('更新成功');location.replace('VAM241.aspx?Code=" + Request["Code"].ToString() + "');"), true);
                    }
                    catch
                    {
                        throw;
                    }
                }
                catch (Exception ex)
                {
                    WaringLogProcess(ex.Message);
                    this.ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0];  //直接取第一個
                }
                finally { Finally_Function(); }

                break;
        }
    }