示例#1
0
    protected void btnAnswer_Click(object sender, EventArgs e)
    {
        if (GXGridView1SelectedValue > 0)
        {
            DistributionDocument dd = DistributionDocument.Get(GXGridView1SelectedValue);

            List <DistributionDocumentItem> lstDDI = DistributionDocumentItem.GetByDistributionDocument(dd.ID);
            if (rblAnswer.SelectedValue == "Accept")
            {
                dd.DocumentStatusID = DistributionDocumentStatuse.GetByCode(DistributionDocumentStatuse.PRIMEN).ID;
                DistributionDocument.Table.Context.SubmitChanges();
                foreach (DistributionDocumentItem ddi in lstDDI)
                {
                    Distribution d = Distribution.Get(ddi.DistributionID);
                    d.DistributionStatusID = DistributionStatuse.GetByCode(DistributionStatuse.POTVRDENA).ID;
                    Distribution.Table.Context.SubmitChanges();
                }
            }
            else if (rblAnswer.SelectedValue == "Deny")
            {
                dd.DocumentStatusID = DistributionDocumentStatuse.GetByCode(DistributionDocumentStatuse.NEPRIFATEN).ID;
                DistributionDocument.Table.Context.SubmitChanges();
                foreach (DistributionDocumentItem ddi in lstDDI)
                {
                    Distribution d = Distribution.Get(ddi.DistributionID);
                    d.DistributionStatusID = DistributionStatuse.GetByCode(DistributionStatuse.VRATENA).ID;
                    d.BranchID             = null;
                    d.UserID = Broker.DataAccess.User.GetFirstSEAdminUser().ID;
                    Distribution.Table.Context.SubmitChanges();
                }
            }
            viewGrid.DataBind();
            mvMain.SetActiveView(viewGrid);
        }
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        DistributionDocType ddt = DistributionDocType.GetByCode(DistributionDocType.POVRATNICA);
        List <Distribution> addedDistributions = new List <Distribution>();
        string endNumber   = tbEndNumber.Text;
        string startNumber = tbStartNumber.Text;
        long   count       = Convert.ToInt64(endNumber) - Convert.ToInt64(startNumber);
        List <Distribution> lstDistributions = new List <Distribution>();
        bool hasErrors = false;

        for (int i = 0; i <= count; i++)
        {
            Distribution d = new Distribution();
            d.Date               = DateTime.Today;
            d.BranchID           = null;
            d.InsuranceCompanyID = int.Parse(ddlInsuranceCompany.SelectedValue);
            d.InsuranceSubTypeID = int.Parse(ddlInsuranceSubType.SelectedValue);
            d.UserID             = Broker.DataAccess.User.GetFirstSEAdminUser().ID;
            string number = (Convert.ToInt64(tbStartNumber.Text) + i).ToString();
            for (int j = 0; j < (endNumber.Length - Convert.ToInt64(number).ToString().Length); j++)
            {
                number = "0" + number;
            }
            Broker.DataAccess.Parameter parHasPrefix = Broker.DataAccess.Parameter.GetByCode(Broker.DataAccess.Parameter.SE_KORISTAT_PREFIKSI);
            if (parHasPrefix != null)
            {
                bool hasPrefix = Convert.ToBoolean(parHasPrefix.Value);
                if (hasPrefix == true)
                {
                    string prefix = tbInsuranceCompanyPrefix.Text;
                    number = prefix + number;
                }
            }
            d.PolicyNumber         = number;
            d.IsUsed               = false;
            d.DistributionStatusID = DistributionStatuse.GetByCode(DistributionStatuse.VRATENA).ID;
            d.ValidateNumberForPovratnica(this.PageUser.BranchID);
            if (d.ValidationErrors.Count > 0)
            {
                hasErrors = true;
                break;
            }
            else
            {
                lstDistributions.Add(d);
            }
        }
        if (hasErrors == false)
        {
            DistributionDocument dd = DistributionDocument.GetByDocumentNumber(tbDocumentNumber.Text);
            if (dd == null)
            {
                dd          = new DistributionDocument();
                dd.BranchID = this.PageUser.BranchID;
                dd.DistributionDocTypeID = ddt.ID;
                dd.DocumentDate          = DateTime.Today;
                dd.DocumentNumber        = tbDocumentNumber.Text;
                dd.DocumentStatusID      = DistributionDocumentStatuse.GetByCode(DistributionDocumentStatuse.ZA_PRIMANjE).ID;
                dd.Description           = tbDescription.Text;
                dd.Insert();
            }
            //Add routes
            DistributionRoute dr = new DistributionRoute();
            dr.Date = DateTime.Today;
            dr.DistributionDocumentID = dd.ID;
            dr.FromNumber             = startNumber;
            dr.ToNumber           = endNumber;
            dr.FromUserID         = this.PageUser.ID;
            dr.ToUserID           = Broker.DataAccess.User.GetFirstSEAdminUser().ID;
            dr.InsuranceCompanyID = Convert.ToInt32(ddlInsuranceCompany.SelectedValue);
            dr.InsuranceSubTypeID = Convert.ToInt32(ddlInsuranceSubType.SelectedValue);
            dr.Insert();
            //Update distributions
            foreach (Distribution distr in lstDistributions)
            {
                Distribution dis = Distribution.Table.Where(c => c.InsuranceCompanyID == distr.InsuranceCompanyID && c.InsuranceSubTypeID == c.InsuranceSubTypeID &&
                                                            c.PolicyNumber == distr.PolicyNumber).SingleOrDefault();
                dis.BranchID             = null;
                dis.DistributionStatusID = DistributionStatuse.GetByCode(DistributionStatuse.VRATENA).ID;
                dis.UserID = Broker.DataAccess.User.GetFirstSEAdminUser().ID;
                Distribution.Table.Context.SubmitChanges();
                DistributionDocumentItem ddi = new DistributionDocumentItem();
                ddi.DistributionDocumentID = dd.ID;
                ddi.DistributionID         = dis.ID;
                ddi.Insert();
                addedDistributions.Add(dis);
            }
            btnPrintDocument.Enabled = true;
            lblError.Text            = "";
            lblError.Visible         = false;
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = "Полисата е искористена или не постои како потврдена во филијала!!";
        }

        gvNewDistrirutions.DataSource = addedDistributions;
        gvNewDistrirutions.DataBind();
        gvDistributions.DataBind();
    }