Beispiel #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            StringBuilder strQuery   = new StringBuilder();
            TechnicalBAL  objTechBAL = new TechnicalBAL();
            VsDtOrder = (DataTable)ViewState["VsDtOrder"];
            int     i = 0;
            string  strReqCode = VsDtOrder.Rows[0]["Requisition"].ToString();
            string  strDocCode = VsDtOrder.Rows[0]["DOCUMENT_CODE"].ToString();
            string  strSuppCode = VsDtOrder.Rows[0]["QUOTATION_SUPPLIER"].ToString();
            string  strOrderCode = VsDtOrder.Rows[0]["ORDER_CODE"].ToString();
            string  strVesselCode = VsDtOrder.Rows[0]["Vessel_Code"].ToString();
            string  strCreatedBy = Session["userid"].ToString();
            string  strPayAt = "On Office";
            decimal dclSuppOrdDiscount = Convert.ToDecimal(VsDtOrder.Rows[0]["suppOrderDiscount"].ToString());
            decimal dclTotalPay = 0, dclRoundOffAmt = 0;

            if (txtAmount.Text.Trim() != "")
            {
                dclTotalPay = Convert.ToDecimal(txtAmount.Text.Trim().ToString());
            }
            else
            {
                dclTotalPay = 0;
            }

            if (txtRoundoff.Text.Trim() != "")
            {
                dclRoundOffAmt = Convert.ToDecimal(txtRoundoff.Text.Trim().ToString());
            }
            else
            {
                dclRoundOffAmt = 0;
            }

            string strSystemCode = VsDtOrder.Rows[0]["ITEM_SYSTEM_CODE"].ToString();
            string strDeptCode = VsDtOrder.Rows[0]["DEPARTMENT"].ToString();
            string strDeliverQty = "", strUpdateROBQty = "", strItemIDs = "";

            foreach (GridDataItem dataItem in rgdDeliveredItems.MasterTableView.Items)
            {
                TextBox txtDeliverdQty = (TextBox)(dataItem.FindControl("txtDeliverdQty") as TextBox);
                Label   txtUpdateROB   = (Label)(dataItem.FindControl("txtUpdateROB") as Label);

                if (txtDeliverdQty.Text.Trim() != "")
                {
                    strDeliverQty   = strDeliverQty + txtDeliverdQty.Text.ToString() + ",";
                    strUpdateROBQty = strUpdateROBQty + txtUpdateROB.Text.ToString() + ",";

                    strItemIDs = strItemIDs + dataItem["ITEM_REF_CODE"].Text.ToString() + ",";

                    i++;
                }
            }

            if (i == 0)
            {
                String msgNoItem = String.Format("alert('Please enter quantity for deliver.')");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgNoItem", msgNoItem, true);
                lblError.Text = "Please enter quantity for deliver.";
            }
            else
            {
                int RetValue = objTechBAL.UpdateDelivery(strReqCode, strDocCode, strSuppCode, strOrderCode,
                                                         strVesselCode, strCreatedBy, strPayAt, dclTotalPay,
                                                         dclRoundOffAmt, strSystemCode, strDeptCode, strItemIDs,
                                                         strDeliverQty, strUpdateROBQty, dclSuppOrdDiscount
                                                         );

                DataTable dtDeliverItem = (DataTable)ViewState["dtDeliverItem"];

                foreach (DataRow dr in dtDeliverItem.Rows)
                {
                    if (dr["ITEM_REF_CODE"].ToString() == "")
                    {
                        strQuery.Append("Insert into [PURC_Dtl_Supply_Items]([ID],ITEM_SYSTEM_CODE,[DOCUMENT_CODE],[ITEM_SERIAL_NO],[REQUISITION_CODE],");
                        strQuery.Append("[ORDER_CODE],[Order_Date],[REQUESTED_QTY],[ITEM_SHORT_DESC],[ORDER_QTY],[ORDER_SUPPLIER],[Vessel_Code],[Created_By],");
                        strQuery.Append("[Date_Of_Creatation],DELIVERY_CODE,ORDER_PRICE,ORDER_RATE,DELIVERD_QTY,Item_delivery_Remarks )");
                        strQuery.Append("(select  Top 1 (select max([ID])+1 from [PURC_Dtl_Supply_Items]),ITEM_SYSTEM_CODE,[DOCUMENT_CODE],0,[REQUISITION_CODE],");
                        strQuery.Append("[ORDER_CODE],[Order_Date],1,'");
                        strQuery.Append(dr["Short_Description"].ToString());
                        strQuery.Append("',1,[ORDER_SUPPLIER],[Vessel_Code],[Created_By],[Date_Of_Creatation],DELIVERY_CODE,'");
                        strQuery.Append(dr["Rate"].ToString());
                        strQuery.Append("','");
                        strQuery.Append(dr["Rate"].ToString());
                        strQuery.Append("','1','" + Convert.ToString(dr["Item_delivery_Remarks"]) + "from [PURC_Dtl_Supply_Items]");
                        strQuery.Append(" where [REQUISITION_CODE]= '");
                        strQuery.Append(strReqCode);
                        strQuery.Append("' and ORDER_CODE='");
                        strQuery.Append(strOrderCode);
                        strQuery.Append("')  ");
                    }
                }

                int val = objTechBAL.ExecuteQuery(strQuery.ToString());

                String msg = String.Format("alert('Delivered Items has been save successfully.')");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg, true);
                lblError.Text = "Delivered Items has been save successfully.";

                //cmbRequisitionList.SelectedIndex = 0;
                FillReq_Catalog();
                BindOrderItem();
                RefreshGrid();

                using (BLL_PURC_Purchase objTechService = new BLL_PURC_Purchase())
                {
                    //Update the requistion Stage Status
                    DataTable dtQuotationList = new DataTable();
                    dtQuotationList.Columns.Add("Qtncode");
                    dtQuotationList.Columns.Add("amount");

                    objTechService.InsertRequisitionStageStatus(Request.QueryString["Requisitioncode"].ToString(), Request.QueryString["Vessel_Code"].ToString(), Request.QueryString["Document_Code"].ToString(), "DLV", " ", Convert.ToInt32(Session["userid"]), dtQuotationList);
                }
            }
        }
        catch (Exception ex)
        {
            //.WriteError(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex);
        }
    }