protected int SaveItems()
    {
        string FinalQuery = HiddenQuery.Value;
        int    retVal     = 0;

        if (FinalQuery != "")
        {
            TechnicalBAL objtechBAL = new TechnicalBAL();
            retVal = objtechBAL.ExecuteQuery(FinalQuery);
        }
        return(retVal);
    }
Esempio n. 2
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);
        }
    }
Esempio n. 3
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (ViewState["strPath"] != null)
            {
                lblErrorMsg.Text = "";
                CheckExcellProcesses();
                string _QuotationCode = DDLSupplier.SelectedValue.Split(new char[] { '~' })[1];

                StringBuilder strQuory = new StringBuilder();
                strQuory.Append("begin try begin tran DECLARE @ifExist int = 0 ,@QuotationCode varchar(30) ='' ,@ItemType int =0 ,@ItemRefCode varchar(30)='0' ");

                Exchange_rate = 1;

                string strPath  = Path.GetDirectoryName((String)ViewState["strPath"].ToString());
                string FileName = Path.GetFileName((String)ViewState["strPath"].ToString());
                string strPath1 = Server.MapPath("TempUpload\\" + FileName).ToString();
                ExlApp     = new Microsoft.Office.Interop.Excel.Application();
                ExlWrkBook = ExlApp.Workbooks.Open(strPath1,
                                                   0,
                                                   true,
                                                   5,
                                                   "", "",
                                                   true,
                                                   Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
                                                   "\t",
                                                   false,
                                                   false,
                                                   0,
                                                   true,
                                                   1,
                                                   0);
                ExlWrkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ExlWrkBook.ActiveSheet;
                if (rgdQuoUpload.MasterTableView.Items.Count != 0)
                {
                    foreach (GridDataItem dataItem in rgdQuoUpload.MasterTableView.Items)
                    {
                        strQuory.Append(" Update dbo.PURC_Dtl_Quoted_Prices Set ");
                        strQuory.Append("QUOTED_RATE='");
                        //strQuory.Append(dr["QUOTED_RATE"].ToString());
                        if (dataItem["Unit_Price"].Text == " ")
                        {
                            strQuory.Append("0");
                        }
                        else
                        {
                            strQuory.Append((Convert.ToDecimal(dataItem["Unit_Price"].Text)).ToString());
                        }
                        strQuory.Append("', QUOTED_DISCOUNT='");
                        if (dataItem["Discount"].Text == "")
                        {
                            strQuory.Append("0");
                        }
                        else
                        {
                            strQuory.Append(dataItem["Discount"].Text);
                        }


                        strQuory.Append("', SURCHARGES='");
                        //if (txtSurcharge.Text.ToString() == "")
                        //{
                        strQuory.Append("0");
                        //}
                        //else
                        //{
                        //    strQuory.Append(txtSurcharge.Text.ToString());
                        //}
                        //strQuory.Append(dr["SURCHARGES%"].ToString());
                        strQuory.Append("', Vat='");
                        if (txtVat.Text.ToString() == "")
                        {
                            strQuory.Append("0");
                        }
                        else
                        {
                            strQuory.Append(txtVat.Text.ToString());
                        }
                        strQuory.Append("', QUOTED_Price='");
                        strQuory.Append(dataItem["Total_Price"].Text);
                        strQuory.Append("',QUOTED_CURRENCY='");
                        strQuory.Append(txtCurrency.Text);
                        strQuory.Append("',QUOTATION_REMARKS='");
                        if (dataItem["Supplier_Remarks"].Text == "" || dataItem["Supplier_Remarks"].Text == " ")
                        {
                            strQuory.Append("");
                        }
                        else
                        {
                            strQuory.Append(dataItem["Supplier_Remarks"].Text.Trim().Replace("'", ""));
                        }
                        strQuory.Append("',Lead_Time='");
                        strQuory.Append(dataItem["LeadTime"].Text);
                        //strQuory.Append(dataItem["column"].Text);

                        strQuory.Append("',Item_Type=154");
                        //if (dataItem["Item_Type"].Text == "Original")
                        //{
                        //    strQuory.Append("ORG");
                        //}
                        //else if (dataItem["Item_Type"].Text == "Imitation")
                        //{
                        //    strQuory.Append("IMT");
                        //}
                        //else
                        //{
                        //    strQuory.Append(dataItem["Item_Type"].Text);
                        //}
                        strQuory.Append(",Additional_Charges='");
                        strQuory.Append(txtAdditionlachrgs.Text);
                        //  strQuory.Append(txtCurrency.Text);
                        strQuory.Append("',Quotation_Status='R',SYNC_FLAG='0',Date_Of_Modified=getdate() where [QUOTATION_CODE]='");
                        strQuory.Append(_QuotationCode);
                        strQuory.Append("' and  [SUPPLIER_CODE]='");
                        strQuory.Append(DDLSupplier.SelectedValue.Split(new char[] { '~' })[0]);
                        strQuory.Append("' and [ITEM_REF_CODE]='");
                        strQuory.Append(dataItem["ITEM_REF_CODE"].Text);
                        strQuory.Append("' and DOCUMENT_CODE='");
                        strQuory.Append(Request.QueryString["Document_Code"].ToString());
                        strQuory.Append("' and Vessel_Code='");
                        strQuory.Append(Request.QueryString["Vessel_Code"].ToString());
                        strQuory.Append("' ");

                        // insert into PURC_DTL_QuotedPrices_ItemType

                        strQuory.Append(@" 
                                         
                                          SELECT  @QuotationCode='" + _QuotationCode + @"' , @ItemType =154  ,@ItemRefCode = '" + dataItem["ITEM_REF_CODE"].Text + @"'            
                                          SET @ifExist=(SELECT COUNT(0) from PURC_DTL_QuotedPrices_ItemType where Quotation_Code=@QuotationCode and Item_Ref_Code=@ItemRefCode  and Item_Type=@ItemType)
                                        IF(isnull(@ifExist,0)!=0)
	                                        BEGIN
	
		                                        UPDATE PURC_DTL_QuotedPrices_ItemType set Quoted_Rate= isnull("         + UDFLib.ConvertToDecimal(dataItem["Unit_Price"].Text.Trim()) + @",0)
		                                        WHERE Quotation_Code=@QuotationCode and Item_Ref_Code=@ItemRefCode  and Item_Type=@ItemType
	                                        END
                                        ELSE 
	                                        BEGIN
		                                        IF(isnull("         + UDFLib.ConvertToDecimal(dataItem["Unit_Price"].Text.Trim()) + @",0) > 0)
			                                        BEGIN
				                                        INSERT INTO PURC_DTL_QuotedPrices_ItemType(ID,Quotation_Code,Item_Ref_Code,Item_Type,Quoted_Rate,Date_Of_Creation)
				                                        SELECT isnull(MAX(id),0)+1,@QuotationCode,@ItemRefCode,@ItemType,isnull("                 + (dataItem["Unit_Price"].Text.Trim() == " " ? "0" : dataItem["Unit_Price"].Text.Trim()) + @",0),GETDATE() FROM PURC_DTL_QuotedPrices_ItemType
			                                        END
	                                        END  
                                                
                                        ");
                    }

                    strQuory.Append("update dbo.PURC_Dtl_REQSN set Currency='");
                    strQuory.Append(txtCurrency.Text);
                    strQuory.Append("',PREVIOUS_EXCHANGE_RATE=1");//the actual value will be saved on po approval
                    if (((Exel.Range)ExlWrkSheet.Cells[7, 3]).Value2.ToString().Trim().Replace("'", "").Length > 250)
                    {
                        lblErrorMsg.Text = "Length of Supplier Quotation Reference should be less than 250 .";
                        strQuory.Clear();
                        return;
                    }
                    else
                    {
                        strQuory.Append(",Supplier_Quotation_Reference='");
                        strQuory.Append(((Exel.Range)ExlWrkSheet.Cells[7, 3]).Value2.ToString().Trim().Replace("'", ""));
                    }

                    strQuory.Append("',Freight_Cost='");
                    strQuory.Append(UDFLib.ConvertToDecimal(((Exel.Range)ExlWrkSheet.Cells[5, 9]).Value2).ToString());
                    strQuory.Append("',Packing_Handling_Charges='");
                    strQuory.Append(UDFLib.ConvertToDecimal(((Exel.Range)ExlWrkSheet.Cells[7, 9]).Value2).ToString());
                    strQuory.Append("',REBATE='");
                    strQuory.Append(UDFLib.ConvertToDecimal(((Exel.Range)ExlWrkSheet.Cells[9, 9]).Value2).ToString());


                    strQuory.Append("',Truck_Cost='");
                    strQuory.Append(txtTruck.Text != "" ? UDFLib.ConvertToDecimal(txtTruck.Text).ToString() : "0");
                    strQuory.Append("',Barge_Workboat_Cost='");
                    strQuory.Append(txtBarge.Text != "" ? UDFLib.ConvertToDecimal(txtBarge.Text).ToString() : "0");
                    strQuory.Append("',Other_Charges='");
                    strQuory.Append(txtAdditionlachrgs.Text != "" ? UDFLib.ConvertToDecimal(txtAdditionlachrgs.Text).ToString() : "0");
                    strQuory.Append("',REASON_TRANS_PKG='");
                    strQuory.Append(txtReasonPKG.Text.Trim().Replace("'", ""));
                    strQuory.Append("',Other_Charges_Reason='");
                    strQuory.Append(txtReasonOther.Text.Trim().Replace("'", ""));
                    strQuory.Append("',QUOTATION_COMMENTS='");
                    strQuory.Append(txtRequi.Text.Trim().Replace("'", ""));
                    strQuory.Append("',DISCOUNT='");
                    strQuory.Append(txtDiscount.Text != "" ? txtDiscount.Text : "0");
                    strQuory.Append("' , Quotation_Status='F' ,Quotation_Status_Date=getdate() where REQUISITION_CODE='");
                    strQuory.Append(Request.QueryString["Requisitioncode"].ToString());
                    strQuory.Append("' and QUOTATION_CODE='");
                    strQuory.Append(_QuotationCode);
                    strQuory.Append("' and QUOTATION_SUPPLIER='");
                    strQuory.Append(DDLSupplier.SelectedValue.Split(new char[] { '~' })[0]);
                    strQuory.Append("' and DOCUMENT_CODE='");
                    strQuory.Append(Request.QueryString["Document_Code"].ToString());
                    strQuory.Append("' and Vessel_Code='");
                    strQuory.Append(Request.QueryString["Vessel_Code"].ToString());
                    strQuory.Append("' ");
                    strQuory.Append("commit tran end try begin catch  DECLARE @ErrorMessage NVARCHAR(4000), @ErrorSeverity INT , @ErrorState INT;SELECT  @ErrorMessage = ERROR_MESSAGE(),  @ErrorSeverity = ERROR_SEVERITY(),  @ErrorState = ERROR_STATE();  RAISERROR (@ErrorMessage,@ErrorSeverity, @ErrorState ); rollback tran end catch");

                    using (BLL_PURC_Purchase objTechService = new BLL_PURC_Purchase())
                    {
                        if (strQuory.Length > 10)
                        {
                            KillExcel();
                            TechnicalBAL objBAL     = new TechnicalBAL();
                            string       FinalQuery = strQuory.ToString();
                            int          valRet     = objBAL.ExecuteQuery(FinalQuery);


                            //int valRet = objTechService.ExequetString(FinalQuery);


                            //string strDestiFileName =Server.MapPath("UploddQuot") + @"\";

                            //Copy the uploaded file into the server.

                            if (System.IO.File.Exists(Server.MapPath("UploadQuot\\" + FileName)) == false)
                            {
                                //FileStream fs = File.Move(Server.MapPath("TempUpload\\" + FileName), Server.MapPath("UploadQuot\\" + FileName));
                                File.Move(Server.MapPath("TempUpload\\" + FileName), Server.MapPath("UploadQuot\\" + FileName));
                                //fs.Close();
                            }

                            string strQuoUpdPath = Server.MapPath("UploadQuot\\").ToString();

                            objTechService.SaveAttachedFileInfo(Request.QueryString["Vessel_Code"].ToString(), Request.QueryString["Requisitioncode"].ToString(), DDLSupplier.SelectedValue.Split(new char[] { '~' })[0], "QUpld", FileName, "UploadQuot/" + FileName, Session["userid"].ToString(), 0);

                            lblErrorMsg.Text = "Quotation has been uploaded sucessfully";

                            String script = String.Format("alert('Quotation has been uploaded sucessfully.');window.close();");
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", script, true);
                        }
                    }
                }
                else
                {
                    lblErrorMsg.Text = "There is no data to upload, Please check the uploaded file.";
                }
            }
            else
            {
                lblErrorMsg.Text = "There is no data to upload, Please check the uploaded file.";
            }
        }
        catch (Exception ex)
        {
            lblErrorMsg.Text = ex.Message;
        }

        finally
        {
            RefreshGrid();
        }
    }