Пример #1
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you want to create new version?", "Warning", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                if (objContract.ContractOID != 0)
                {
                    // get old object
                    Contract oldContract = new Contract();
                    oldContract = SCBase.searchContracts(SCMain.ContractOid);
                    //update status old then save
                    oldContract.ContractStatus = ContractStatus.Deactivated;

                    //Load danh sach ContractOption va ZSC_SubcontractorContractRisk
                    List <ContractOption> oldContractOptions             = ContractOption.getContractOption(SCMain.ContractOid);
                    List <ZSC_SubcontractorContractRisk> oldContractRisk = ZSC_SubcontractorContractRisk.getSubcontractorContractRisk(SCMain.ContractOid);

                    oldContract.saveContract();


                    //  new object
                    objContract.ContractOID = 0;
                    objContract.VersionNo   = objContract.VersionNo + 1;
                    this.updateContract();

                    //Tao list [ZSC_ContractOption]
                    objContract.listContractOptions = oldContractOptions;
                    if (objContract.listContractOptions != null && objContract.listContractOptions.Count > 0)
                    {
                        foreach (ContractOption objOptionDetail in objContract.listContractOptions)
                        {
                            objOptionDetail.isInsert = true;
                        }
                    }

                    //Tao list [ZSC_SubcontractorContractRisk]
                    objContract.SubcontractorContractRisks = oldContractRisk;


                    bool tmp = objContract.saveContract();
                    if (tmp)
                    {
                        this.loadComboboxData();
                        this.loadContractData();

                        //Load Data
                        this.loadVehice();
                        this.contractOption1.loadDataGrid();
                        this.contractOption1.loadTree();
                        this.contractDataFrm.fillData();
                    }
                }
            }
            else
            {
                //MessageBox.Show("Ha ha");
            }
        }
Пример #2
0
        private void fillRisk()
        {
            List <ZSC_SubcontractorContractRisk> lstContractRisk = ContractFrm.objContract.loadZSC_SubcontractorContractRisk();

            dataTable = ObjectUtils.ConvertToDataTable(lstContractRisk);

            //Add Column subcontracter
            List <SubContractorContract> SubContracts = ContractFrm.objContract.SubContracts;

            List <ZSC_SubcontractorContractRisk> listRiskSub = null;

            foreach (SubContractorContract subContract in SubContracts)
            {
                dataTable.Columns.Add("sub" + subContract.OID, typeof(Int32));
            }

            ZSC_SubcontractorContractRisk contractRisk = null;

            foreach (SubContractorContract subContract in SubContracts)
            {
                listRiskSub = ZSC_SubcontractorContractRisk.getContractRiskBySub(ContractFrm.objContract.ContractOID, subContract.OID);
                if (listRiskSub.Count > 0)
                {
                    foreach (DataRow row in dataTable.Rows)
                    {
                        contractRisk = null;
                        contractRisk = listRiskSub.SingleOrDefault(s => s.RiskPartnerCustId == Int32.Parse(row["RiskPartnerCustId"].ToString()));
                        if (contractRisk != null)
                        {
                            row["sub" + subContract.OID] = contractRisk.RiskLevel;
                        }
                        else
                        {
                            row["sub" + subContract.OID] = 0;
                        }
                    }
                }
                else
                {
                    foreach (DataRow row in dataTable.Rows)
                    {
                        row["sub" + subContract.OID] = 0;
                    }
                }
            }
        }
Пример #3
0
        public Contract saveContractData()
        {
            //ContractDate contractDate = contract.ContractDateData;
            //ContractPayment ContractPaymentData = contract.ContractPaymentData;
            //ContractCapital ContractCapitalData = contract.ContractCapitalData;
            //ContractCost ContractCostData = contract.ContractCostData;
            //ContractExtraKm ContractExtraKmData = contract.ContractExtraKmData;

            ContractDate    contractDate        = ContractFrm.objContract.ContractDateData;
            ContractPayment ContractPaymentData = ContractFrm.objContract.ContractPaymentData;
            ContractCapital ContractCapitalData = ContractFrm.objContract.ContractCapitalData;
            ContractCost    ContractCostData    = ContractFrm.objContract.ContractCostData;
            ContractExtraKm ContractExtraKmData = ContractFrm.objContract.ContractExtraKmData;

            if (contractDate == null)
            {
                contractDate = new ContractDate();
            }
            if (ContractPaymentData == null)
            {
                ContractPaymentData = new ContractPayment();
            }
            if (ContractCapitalData == null)
            {
                ContractCapitalData = new ContractCapital();
            }
            if (ContractCostData == null)
            {
                ContractCostData = new ContractCost();
            }
            if (ContractExtraKmData == null)
            {
                ContractExtraKmData = new ContractExtraKm();
            }

            //Start
            contractDate.ContractStartDate   = txtStartDate.Value;
            contractDate.ContractStartKm     = Int32.Parse(txtStartKm.Value.ToString());
            contractDate.ContractStartHour   = Int32.Parse(txtStartHr.Value.ToString());
            contractDate.InvoiceStartDate    = txtStartInvoice.Value;
            contractDate.ContractPeriodMonth = Int32.Parse(txtPeriod.Text);
            contractDate.ContractPeriodKm    = Int32.Parse(txtKm.Value.ToString());
            contractDate.ContractPeriodHour  = Int32.Parse(txtHr.Value.ToString());


            if (rdKmBase.Checked)
            {
                ContractFrm.objContract.ContractDateData.ContractPeriodKmHour = 1;
            }
            if (rdHrBase.Checked)
            {
                ContractFrm.objContract.ContractDateData.ContractPeriodKmHour = 2;
            }

            //End
            contractDate.ContractEndDate = txtEndDate.Value;
            contractDate.ContractEndKm   = Int32.Parse(txtEndKm.Value.ToString());
            contractDate.ContractEndHour = Int32.Parse(txtEndHr.Value.ToString());
            contractDate.InvoiceEndDate  = txtEndInvoice.Value;

            if (cbTemType.SelectedValue != null)
            {
                clsBaseListItem TerminationType = new clsBaseListItem();
                TerminationType.strValue1 = cbTemType.SelectedValue.ToString();
                TerminationType.strText   = cbTemType.SelectedText;
                ContractFrm.objContract.TerminationType = TerminationType;
            }

            //Payment
            if (cbPayPeriod.SelectedValue != null)
            {
                clsBaseListItem PaymentPeriod = new clsBaseListItem();
                PaymentPeriod.strValue1           = cbPayPeriod.SelectedValue.ToString();
                PaymentPeriod.strText             = cbPayPeriod.SelectedText;
                ContractPaymentData.PaymentPeriod = PaymentPeriod;
            }


            ContractFrm.objContract.IsManualInvoice = cbInvoice.Checked;
            ContractPaymentData.PaymentIsInBlock    = cbPayment.Checked;

            if (cbColType.SelectedValue != null)
            {
                ContractPaymentData.PaymentCollectionType = cbColType.SelectedValue.ToString();
            }
            if (cbGrpLevel.SelectedValue != null)
            {
                ContractPaymentData.PaymentGroupingLevel = cbGrpLevel.SelectedValue.ToString();
            }
            clsBaseListItem PaymentTerm = new clsBaseListItem();

            if (cbPayTerm.SelectedValue != null)
            {
                PaymentTerm.strValue1 = cbPayTerm.SelectedValue.ToString();
                PaymentTerm.strText   = cbPayTerm.SelectedText;
            }
            ContractPaymentData.PaymentTerm = PaymentTerm;

            clsBaseListItem InvoiceSiteId = new clsBaseListItem();

            if (cbInvoiceSite.SelectedValue != null)
            {
                InvoiceSiteId.strValue1 = cbInvoiceSite.SelectedValue.ToString();
                InvoiceSiteId.strText   = cbInvoiceSite.SelectedText;
            }
            ContractFrm.objContract.InvoiceSiteId = InvoiceSiteId;


            //captial
            ContractCapitalData.CapitalStartAmount = txtStartAmount.Value;
            clsBaseListItem CapitalStartPayer = new clsBaseListItem();

            if (txtStartAmountPayer.SelectedValue != null)
            {
                CapitalStartPayer.strValue1 = txtStartAmountPayer.SelectedValue.ToString();
                CapitalStartPayer.strText   = txtStartAmountPayer.SelectedText.ToString();
            }
            ContractCapitalData.CapitalStartPayer = CapitalStartPayer;

            ContractCapitalData.CapitalMonthAmount = txtMonAmount.Value;

            clsBaseListItem CapitalMonthPayer = new clsBaseListItem();

            if (txtMonAmountPayer.SelectedValue != null)
            {
                CapitalMonthPayer.strValue1 = txtMonAmountPayer.SelectedValue.ToString();
                CapitalMonthPayer.strText   = txtMonAmountPayer.SelectedText.ToString();
            }
            ContractCapitalData.CapitalMonthPayer = CapitalMonthPayer;

            if (ContractFrm.objContract.ContractCapitalData != null)
            {
                txtTotalAmount.Text = (ContractFrm.objContract.ContractCapitalData.CapitalStartAmount
                                       + ContractFrm.objContract.ContractCapitalData.CapitalMonthAmount * ContractFrm.objContract.ContractDateData.ContractPeriodMonth).ToString();
            }
            else
            {
                txtTotalAmount.Text = "";
            }

            //Cost
            clsBaseListItem CostBasis = new clsBaseListItem();

            if (cbCostBassis.SelectedValue != null)
            {
                CostBasis.strValue1 = cbCostBassis.SelectedValue.ToString();
                CostBasis.strText   = cbCostBassis.SelectedText.ToString();
            }
            ContractCostData.CostBasis = CostBasis;

            ContractCostData.CostBasedOnService = txtCostBase.Value;
            ContractCostData.CostMonthBasis     = txtMonBassis.Value;
            ContractCostData.CostKmBasis        = txtKmBassis.Value;
            ContractCostData.CostPerKm          = txtErr.Value;
            txtLastPay.Text = "txtLastPay";
            txtLastKm.Text  = "";

            //Extra

            clsBaseListItem ExtraKmInvoicePeriod = new clsBaseListItem();

            if (cbBiling.SelectedValue != null)
            {
                ExtraKmInvoicePeriod.strValue1 = cbBiling.SelectedValue.ToString();
                ExtraKmInvoicePeriod.strText   = cbBiling.SelectedText.ToString();
            }
            ContractExtraKmData.ExtraKmInvoicePeriod = ExtraKmInvoicePeriod;

            clsBaseListItem ExtraKmAccounting = new clsBaseListItem();

            if (cbAccounting.SelectedValue != null)
            {
                ExtraKmAccounting.strValue1 = cbAccounting.SelectedValue.ToString();
                ExtraKmAccounting.strText   = cbAccounting.SelectedText.ToString();
            }
            ContractExtraKmData.ExtraKmAccounting     = ExtraKmAccounting;
            ContractExtraKmData.ExtraKmMaxDeviation   = txtMaxDev.Value;
            ContractExtraKmData.ExtraKmLowAmount      = txtLowKm.Value;
            ContractExtraKmData.ExtraKmHighAmount     = txtHighKm.Value;
            ContractExtraKmData.ExtraKmInvoicedAmount = txtInvoiceAmount.Value;

            //
            clsBaseListItem RollingCode = new clsBaseListItem();

            if (cbRoll.SelectedIndex >= 0)
            {
                RollingCode.strValue1 = cbRoll.SelectedValue.ToString();
                RollingCode.strText   = cbRoll.SelectedText.ToString();
            }
            ContractFrm.objContract.RollingCode = RollingCode;

            ContractFrm.objContract.IsInvoiceDetail = cbInvoiceDetail.Checked;

            //RiskCustId

            ContractCustomer RiskCustId = new ContractCustomer();

            if (txtRiskCusId.Text != null && txtRiskCusId.Text.Trim().Length > 0)
            {
                RiskCustId.CustId = Int32.Parse(txtRiskCusId.Text);
            }
            ContractFrm.objContract.RiskCustId = RiskCustId;
            ContractFrm.objContract.RiskLevel  = txtRishLevel.Value;



            //Save Risk
            List <ZSC_SubcontractorContractRisk> listRisk     = new List <ZSC_SubcontractorContractRisk>();
            List <SubContractorContract>         SubContracts = ContractFrm.objContract.SubContracts;

            ZSC_SubcontractorContractRisk objRisk = null;
            string  colName = "";
            decimal newInteger;

            foreach (DataRow row in dataTable.Rows)
            {
                foreach (SubContractorContract subContract in SubContracts)
                {
                    colName = "sub" + subContract.OID;
                    if (row[colName] != null && row[colName].ToString().Trim().Length > 0 &&
                        decimal.TryParse(row[colName].ToString().Trim(), out newInteger) && newInteger > 0)
                    {
                        objRisk = new ZSC_SubcontractorContractRisk();
                        objRisk.SubContractOID    = subContract.OID;
                        objRisk.RiskPartnerCustId = Int32.Parse(row["RiskPartnerCustId"].ToString().Trim());
                        objRisk.RiskLevel         = decimal.Parse(row[colName].ToString().Trim());
                        listRisk.Add(objRisk);
                    }
                }
            }
            ContractFrm.objContract.SubcontractorContractRisks = listRisk;
            ContractFrm.objContract.ContractDateData           = contractDate;
            ContractFrm.objContract.ContractPaymentData        = ContractPaymentData;
            ContractFrm.objContract.ContractCapitalData        = ContractCapitalData;
            ContractFrm.objContract.ContractCostData           = ContractCostData;
            ContractFrm.objContract.ContractExtraKmData        = ContractExtraKmData;

            ContractFrm.objContract.IndexingDate = dtIndexingDate.Value;
            ContractFrm.objContract.IndexValue   = dfIndexValue.Value;
            ContractFrm.objContract.ContractPaymentData.InvoiceDate = (Int32)dfInvoicingDay.Value;
            return(ContractFrm.objContract);
        }