private void ContractSave()
        {
            Business.Service.Contract objContract = new Business.Service.Contract();
            Entity.Service.Contract   contract    = new Entity.Service.Contract();

            contract.CreatedBy         = int.Parse(HttpContext.Current.User.Identity.Name);
            contract.ContractId        = 0;
            contract.CustomerId        = CustomerMasterId;
            contract.ContractTypeId    = int.Parse(ddlContractType.SelectedValue);
            contract.ContractStartDate = (!String.IsNullOrEmpty(txtContractStartDate.Text.Trim())) ? Convert.ToDateTime(txtContractStartDate.Text.Trim()) : DateTime.MinValue;
            contract.ContractEndDate   = (!String.IsNullOrEmpty(txtContractEndDate.Text.Trim())) ? Convert.ToDateTime(txtContractEndDate.Text.Trim()) : DateTime.MinValue;

            using (DataTable dtContractDetails = new DataTable())
            {
                dtContractDetails.Columns.Add("CustomerPurchaseId");
                dtContractDetails.Columns.Add("A3BWStartMeter");
                dtContractDetails.Columns.Add("A4BWStartMeter");
                dtContractDetails.Columns.Add("A3CLStartMeter");
                dtContractDetails.Columns.Add("A4CLStartMeter");
                dtContractDetails.Columns.Add("A3BWPages");
                dtContractDetails.Columns.Add("A4BWPages");
                dtContractDetails.Columns.Add("A3CLPages");
                dtContractDetails.Columns.Add("A4CLPages");
                dtContractDetails.Columns.Add("A3BWRate");
                dtContractDetails.Columns.Add("A4BWRate");
                dtContractDetails.Columns.Add("A3CLRate");
                dtContractDetails.Columns.Add("A4CLRate");

                foreach (GridViewRow gvr in gvCustomerPurchaseListForContract.Rows)
                {
                    if (((CheckBox)gvr.FindControl("chkSelect")).Checked)
                    {
                        dtContractDetails.Rows.Add();
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["CustomerPurchaseId"] = gvCustomerPurchaseListForContract.DataKeys[gvr.RowIndex].Values[0].ToString();
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3BWStartMeter"]     = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3BWStartMeter")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3BWStartMeter")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4BWStartMeter"]     = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4BWStartMeter")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4BWStartMeter")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3CLStartMeter"]     = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3CLStartMeter")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3CLStartMeter")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4CLStartMeter"]     = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4CLStartMeter")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4CLStartMeter")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3BWPages"]          = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3BWPage")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3BWPage")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4BWPages"]          = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4BWPage")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4BWPage")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3CLPages"]          = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3CLPage")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3CLPage")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4CLPages"]          = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4CLPage")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4CLPage")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3BWRate"]           = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3BWRate")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3BWRate")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4BWRate"]           = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4BWRate")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4BWRate")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3CLRate"]           = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA3CLRate")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA3CLRate")).Text.Trim() : "";
                        dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4CLRate"]           = (!String.IsNullOrEmpty(((TextBox)gvr.FindControl("txtA4CLRate")).Text.Trim())) ? ((TextBox)gvr.FindControl("txtA4CLRate")).Text.Trim() : "";

                        dtContractDetails.AcceptChanges();

                        //updating last meter reading in Customer Purchase
                        Business.Service.ServiceBook objServiceBook = new Business.Service.ServiceBook();
                        Entity.Service.ServiceBook   serviceBook    = new Entity.Service.ServiceBook();
                        serviceBook.CustomerPurchaseId = Convert.ToInt32(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["CustomerPurchaseId"]);
                        serviceBook.A3BWMeterReading   = string.IsNullOrEmpty(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3BWStartMeter"].ToString()) ? 0
                                                        : Convert.ToInt32(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3BWStartMeter"]);
                        serviceBook.A4BWMeterReading = string.IsNullOrEmpty(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4BWStartMeter"].ToString()) ? 0
                                                        : Convert.ToInt32(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4BWStartMeter"]);
                        serviceBook.A3CLMeterReading = string.IsNullOrEmpty(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3CLStartMeter"].ToString()) ? 0
                                                        : Convert.ToInt32(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A3CLStartMeter"]);
                        serviceBook.A4CLMeterReading = string.IsNullOrEmpty(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4CLStartMeter"].ToString()) ? 0
                                                        : Convert.ToInt32(dtContractDetails.Rows[dtContractDetails.Rows.Count - 1]["A4CLStartMeter"]);

                        int response = 0;
                        response = objServiceBook.Service_MeterReading_Update(serviceBook);

                        if (response == 0)
                        {
                            Message1.IsSuccess = false;
                            Message1.Text      = "Current meter reading unable to update! Please add new entry or contact admin.";
                            Message1.Show      = true;
                            ModalPopupExtender2.Show();
                            return;
                        }
                    }
                }

                if (dtContractDetails.Rows.Count > 0)
                {
                    contract.ContractDetails = dtContractDetails;
                }
                else
                {
                    Message1.IsSuccess = false;
                    Message1.Text      = "Please select atleast 1 machine.";
                    Message1.Show      = true;
                    ModalPopupExtender2.Show();
                    return;
                }
            }
            int retVal = objContract.Save(contract);

            if (retVal > 0)
            {
                LoadContractList();
                ClearControlForContract();

                Message1.IsSuccess = true;
                Message1.Text      = "Data saved.";
                Message1.Show      = true;
                ModalPopupExtender2.Show();
            }
            else
            {
                Message1.IsSuccess = false;
                Message1.Text      = "Data not saved";
                Message1.Show      = true;
                ModalPopupExtender2.Show();
            }
        }
Example #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ComplainValidation())
            {
                Business.Service.TonerRequest objTonnerRequest = new Business.Service.TonerRequest();
                Entity.Service.TonerRequest   tonnerRequest    = new Entity.Service.TonerRequest();
                Business.Service.ServiceBook  objServiceBook   = new Business.Service.ServiceBook();
                Entity.Service.ServiceBook    serviceBook      = new Entity.Service.ServiceBook();

                foreach (GridViewRow gvr in gvPurchase.Rows)
                {
                    if (((CheckBox)gvr.FindControl("chk")).Checked)
                    {
                        tonnerRequest.CustomerPurchaseId = int.Parse(gvPurchase.DataKeys[gvr.RowIndex].Values[0].ToString());
                        serviceBook.CustomerPurchaseId   = int.Parse(gvPurchase.DataKeys[gvr.RowIndex].Values[0].ToString());
                    }
                }

                tonnerRequest.CustomerId      = int.Parse(HttpContext.Current.User.Identity.Name.Split('|')[(int)Constants.Customer.ID]);;
                tonnerRequest.RequestNo       = "";
                tonnerRequest.RequestDateTime = DateTime.Now;
                tonnerRequest.isCustomerEntry = true;
                tonnerRequest.CallStatusId    = (int)CallStatusType.TonerRequestInQueue;
                if (txtA3BWMeterReading.Text.Trim() == string.Empty)
                {
                    tonnerRequest.A3BWMeterReading = null;
                }
                else
                {
                    tonnerRequest.A3BWMeterReading = int.Parse(txtA3BWMeterReading.Text.Trim());
                }
                if (txtA4BWMeterReading.Text.Trim() == string.Empty)
                {
                    tonnerRequest.A4BWMeterReading = null;
                }
                else
                {
                    tonnerRequest.A4BWMeterReading = int.Parse(txtA4BWMeterReading.Text.Trim());
                }
                if (txtA3CLMeterReading.Text.Trim() == string.Empty)
                {
                    tonnerRequest.A3CLMeterReading = null;
                }
                else
                {
                    tonnerRequest.A3CLMeterReading = int.Parse(txtA3CLMeterReading.Text.Trim());
                }
                if (txtA4CLMeterReading.Text.Trim() == string.Empty)
                {
                    tonnerRequest.A4CLMeterReading = null;
                }
                else
                {
                    tonnerRequest.A4CLMeterReading = int.Parse(txtA4CLMeterReading.Text.Trim());
                }
                tonnerRequest.Remarks   = txtRequest.Text.Trim();
                tonnerRequest.CreatedBy = int.Parse(HttpContext.Current.User.Identity.Name.Split('|')[(int)Constants.Customer.ID]);

                foreach (GridViewRow toner in gvTonner.Rows)
                {
                    if (((CheckBox)toner.FindControl("chk1")).Checked)
                    {
                        tonnerRequest.SpareIds.Add(new TonerIdQuantity
                        {
                            TonerId  = long.Parse(gvTonner.DataKeys[toner.RowIndex].Values[0].ToString()),
                            Quantity = int.Parse(((TextBox)toner.FindControl("txtRequisiteQty")).Text)
                        });
                    }
                }

                if (txtA3BWMeterReading.Text.Trim() == string.Empty)
                {
                    serviceBook.A3BWMeterReading = null;
                }
                else
                {
                    serviceBook.A3BWMeterReading = int.Parse(txtA3BWMeterReading.Text.Trim());
                }
                if (txtA4BWMeterReading.Text.Trim() == string.Empty)
                {
                    serviceBook.A4BWMeterReading = null;
                }
                else
                {
                    serviceBook.A4BWMeterReading = int.Parse(txtA4BWMeterReading.Text.Trim());
                }
                if (txtA3CLMeterReading.Text.Trim() == string.Empty)
                {
                    serviceBook.A3CLMeterReading = null;
                }
                else
                {
                    serviceBook.A3CLMeterReading = int.Parse(txtA3CLMeterReading.Text.Trim());
                }
                if (txtA4CLMeterReading.Text.Trim() == string.Empty)
                {
                    serviceBook.A4CLMeterReading = null;
                }
                else
                {
                    serviceBook.A4CLMeterReading = int.Parse(txtA4CLMeterReading.Text.Trim());
                }

                DataTable dtTonnerRequest     = objTonnerRequest.Service_TonerRequest_Save(tonnerRequest);
                bool      isTonerLowYield     = objTonnerRequest.Service_TonerLowYieldCheck(tonnerRequest);
                int       meterUpdateResponse = objServiceBook.Service_MeterReading_Update(serviceBook);

                if (dtTonnerRequest.Rows.Count > 0 && meterUpdateResponse > 0)
                {
                    string message = "Toner request received. Your request no : " + dtTonnerRequest.Rows[0]["TonnerRequestNo"].ToString() + ". ";

                    /* Checking whether machine is in contract or not*/
                    Business.Service.Contract objContract = new Business.Service.Contract();
                    int approvalResponse = Approval_Save(tonnerRequest, dtTonnerRequest, isTonerLowYield);

                    if (!objContract.Service_MachineIsInContractCheck(CustomerPurchaseId) || isTonerLowYield) //Out of Contract AND Low Yield
                    {
                        if (approvalResponse > 0)
                        {
                            //Appending low toner warning
                            message += Server.HtmlDecode("<span style='color:red'>Warning: Your request is under verification</span>");
                            //SentNotification(objServiceBook, dtTonnerRequest);
                        }
                    }
                    ResetControls(dtTonnerRequest);
                    Message.IsSuccess = true;
                    Message.Text      = message;
                }
                else
                {
                    Message.IsSuccess = false;
                    Message.Text      = "Sorry! we can not receive your request. Please try again.";
                }
                Message.Show = true;
            }
        }