コード例 #1
0
        /// <summary>
        ///     加载页面数据
        /// </summary>
        private void LoadData()
        {
            switch (Actions)
            {
            case WebAction.Add:
                txtKeyId.Text = SequenceService.CreateSequence("TM", CurrentUser.AccountComId);
                Region1.Title = "添加核销收单";

                var temp = new LHSKOrderChecked
                {
                    KeyId = txtKeyId.Text,

                    FFlag = 1,

                    FDeleteFlag = 1,

                    CreateBy = CurrentUser.AccountName,

                    FDate = txtFDate.SelectedDate,

                    FAmount = 0,

                    FCate = "客户",

                    FCompanyId = CurrentUser.AccountComId,
                };

                //临时写入单据
                CheckedOrderService.Add(temp);


                //    var summary = new JObject
                //{
                //    {"FCode", "合计"},
                //    {"FAmt", 0},
                //};

                //    Grid1.SummaryData = summary;

                break;

            case WebAction.Edit:
                Region1.Title = "编辑核销收单";
                txtKeyId.Text = KeyId;
                if (CheckedOrder != null)
                {
                    txtFCode.Text     = CheckedOrder.FCode;
                    tbxFCustomer.Text = CheckedOrder.FName;
                    txtFMemo.Text     = CheckedOrder.FMemo;

                    BindDataGrid();
                }
                break;
            }
        }
コード例 #2
0
        /// <summary>
        ///     提交编辑
        /// </summary>
        private bool SubmintEdit()
        {
            if (CheckedOrder != null)
            {
                CheckedOrder.FCode = txtFCode.Text;
                CheckedOrder.FName = tbxFCustomer.Text;

                CheckedOrder.FMemo = txtFMemo.Text.Trim();

                return(CheckedOrderService.SaveChanges() >= 0);
            }
            return(false);
        }
コード例 #3
0
        /// <summary>
        ///     提交添加
        /// </summary>
        private bool SubmintAdd()
        {
            var order = CheckedOrderService.Where(p => p.KeyId == txtKeyId.Text.Trim() && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault();

            if (order != null)
            {
                //核销主单据
                //--------------------------------------------------
                order.FCode = txtFCode.Text;
                order.FName = tbxFCustomer.Text;
                //--------------------------------------------------
                order.FDeleteFlag = 0;
                order.FMemo       = txtFMemo.Text.Trim();
                order.CreateBy    = CurrentUser.AccountName;
                order.FDate       = txtFDate.SelectedDate;
                order.FCompanyId  = CurrentUser.AccountComId;

                //本次实际核销的金额
                decimal checkedAmt = 0.00M;

                //收款单
                decimal sksum = 0.00M;
                int[]   sks   = Grid1.SelectedRowIndexArray;

                for (int i = 0; i < sks.Length; i++)
                {
                    sksum += Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2].ToString());
                }

                if (sksum <= 0)
                {
                    Alert.Show("要核销的收款单已核销完,暂无需核销单据。", MessageBoxIcon.Information);
                    return(false);
                }

                //销售金额
                decimal salesum = 0.00M;
                int[]   sales   = Grid2.SelectedRowIndexArray;

                for (int i = 0; i < sales.Length; i++)
                {
                    salesum += Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1].ToString());
                }

                if (sksum <= 0)
                {
                    Alert.Show("要核销的发货单已核销完,暂无需核销单据。", MessageBoxIcon.Information);
                    return(false);
                }

                if (sksum == salesum)
                {
                    //实际核销款
                    checkedAmt = sksum;

                    for (int i = 0; i < sks.Length; i++)
                    {
                        int    id    = Convert.ToInt32(Grid1.DataKeys[sks[i]][1].ToString());
                        string keyid = Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][0].ToString();
                        var    banks = new LHSKOrderCheckedBanks();
                        banks.KeyId      = txtKeyId.Text;
                        banks.CBankId    = id;
                        banks.FAmt       = Convert.ToDecimal(Grid1.DataKeys[sks[i]][2]);
                        banks.FCompanyId = CurrentUser.AccountComId;

                        var bank = CheckedOrderBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault();
                        if (bank != null)
                        {
                            CheckedOrderBanksService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderBanksService.Add(banks);
                        }
                    }
                    for (int i = 0; i < sales.Length; i++)
                    {
                        string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString();

                        var details = new LHSKOrderCheckedDetails();
                        details.KeyId      = txtKeyId.Text;
                        details.FSaleKeyId = keyid;
                        details.FAmount    = Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1]);
                        details.FCompanyId = CurrentUser.AccountComId;

                        var detail =
                            CheckedOrderDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId)
                            .FirstOrDefault();

                        if (detail != null)
                        {
                            CheckedOrderDetailsService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderDetailsService.Add(details);
                        }
                    }
                }
                else if (sksum > salesum)
                {
                    //实际核销款
                    checkedAmt = salesum;

                    //分析
                    decimal kfpje = salesum;
                    for (int i = 0; i < sks.Length; i++)
                    {
                        int id = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][1].ToString());
                        /////////////////////////////////////////////////
                        var sk = Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2]);

                        decimal hxje = 0.00M;
                        decimal yszj = sk;
                        if (kfpje == 0)
                        {
                            hxje = 0;
                        }
                        else
                        {
                            decimal kyje = kfpje - yszj;

                            if (kyje > 0)
                            {
                                hxje  = yszj;
                                kfpje = kyje;
                            }
                            else if (kyje == 0)
                            {
                                hxje  = kfpje;
                                kfpje = kyje;
                            }
                            else
                            {
                                hxje  = kfpje;
                                kfpje = 0;
                            }
                        }

                        /////////////////////////////////////////////////
                        var banks = new LHSKOrderCheckedBanks();
                        banks.KeyId      = txtKeyId.Text;
                        banks.CBankId    = id;
                        banks.FCompanyId = CurrentUser.AccountComId;

                        //本次核销款
                        banks.FAmt = hxje;

                        var bank =
                            CheckedOrderBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId)
                            .FirstOrDefault();
                        if (bank != null)
                        {
                            CheckedOrderBanksService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderBanksService.Add(banks);
                        }
                    }
                    /////////////////////////////////////////////////
                    decimal kfpje2 = salesum;
                    for (int i = 0; i < sales.Length; i++)
                    {
                        string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString();
                        //////////////////////////////////////////////////////////
                        var     sale = Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1]);
                        decimal hxje = 0.00M;
                        decimal yszj = sale;
                        if (kfpje2 == 0)
                        {
                            hxje = 0;
                        }
                        else
                        {
                            decimal kyje = kfpje2 - yszj;

                            if (kyje > 0)
                            {
                                hxje   = yszj;
                                kfpje2 = kyje;
                            }
                            else if (kyje == 0)
                            {
                                hxje   = kfpje2;
                                kfpje2 = kyje;
                            }
                            else
                            {
                                hxje  = kfpje2;
                                kfpje = 0;
                            }
                        }
                        /////////////////////////////////////////////////////////
                        var details = new LHSKOrderCheckedDetails();
                        details.KeyId      = txtKeyId.Text;
                        details.FSaleKeyId = keyid;
                        details.FAmount    = hxje;
                        details.FCompanyId = CurrentUser.AccountComId;

                        var detail =
                            CheckedOrderDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId)
                            .FirstOrDefault();

                        if (detail != null)
                        {
                            CheckedOrderDetailsService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderDetailsService.Add(details);
                        }
                    }
                }
                else
                {
                    //实际核销款
                    checkedAmt = sksum;

                    //分析
                    decimal kfpje = sksum;
                    for (int i = 0; i < sks.Length; i++)
                    {
                        int id = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][1].ToString());
                        //string keyid = Grid1.DataKeys[sks[i]][0].ToString();
                        /////////////////////////////////////////////////
                        var sk = Convert.ToDecimal(Grid1.DataKeys[Grid1.SelectedRowIndexArray[i]][2]);

                        decimal hxje = 0.00M;

                        decimal yszj = sk;

                        if (kfpje == 0)
                        {
                            hxje = 0;
                        }
                        else
                        {
                            decimal kyje = kfpje - yszj;

                            if (kyje > 0)
                            {
                                hxje  = yszj;
                                kfpje = kyje;
                            }
                            else if (kyje == 0)
                            {
                                hxje  = kfpje;
                                kfpje = kyje;
                            }
                            else
                            {
                                hxje  = kfpje;
                                kfpje = 0;
                            }
                        }

                        /////////////////////////////////////////////////
                        var banks = new LHSKOrderCheckedBanks();
                        banks.KeyId      = txtKeyId.Text;
                        banks.CBankId    = id;
                        banks.FCompanyId = CurrentUser.AccountComId;

                        //本次核销款
                        banks.FAmt = hxje;

                        var bank = CheckedOrderBanksService.Where(p => p.KeyId == txtKeyId.Text && p.CBankId == id && p.FCompanyId == CurrentUser.AccountComId).FirstOrDefault();
                        if (bank != null)
                        {
                            CheckedOrderBanksService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderBanksService.Add(banks);
                        }
                    }


                    decimal kfpje2 = sksum;
                    for (int i = 0; i < sales.Length; i++)
                    {
                        string keyid = Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][0].ToString();
                        //////////////////////////////////////////////////////////
                        var     sale = Convert.ToDecimal(Grid2.DataKeys[Grid2.SelectedRowIndexArray[i]][1]);
                        decimal hxje = 0.00M;
                        decimal yszj = sale;
                        if (kfpje2 == 0)
                        {
                            hxje = 0;
                        }
                        else
                        {
                            decimal kyje = kfpje2 - yszj;

                            if (kyje > 0)
                            {
                                hxje   = yszj;
                                kfpje2 = kyje;
                            }
                            else if (kyje == 0)
                            {
                                hxje   = kfpje2;
                                kfpje2 = kyje;
                            }
                            else
                            {
                                hxje  = kfpje2;
                                kfpje = 0;
                            }
                        }

                        var details = new LHSKOrderCheckedDetails();
                        details.KeyId      = txtKeyId.Text;
                        details.FSaleKeyId = keyid;
                        details.FAmount    = hxje;
                        details.FCompanyId = CurrentUser.AccountComId;

                        var detail =
                            CheckedOrderDetailsService.Where(p => p.KeyId == txtKeyId.Text && p.FSaleKeyId == keyid && p.FCompanyId == CurrentUser.AccountComId)
                            .FirstOrDefault();

                        if (detail != null)
                        {
                            CheckedOrderDetailsService.SaveChanges();
                        }
                        else
                        {
                            CheckedOrderDetailsService.Add(details);
                        }
                    }
                }


                //-----------------------------------------------------
                //实际核销款
                order.FAmount = checkedAmt;

                CheckedOrderService.SaveChanges();

                //-----------------------------------------------------
                if (txtKeyId.Text.Contains("TM"))
                {
                    //单据号问题
                    string newKeyId   = SequenceService.CreateSequence(Convert.ToDateTime(txtFDate.SelectedDate), "HR", CurrentUser.AccountComId);
                    var    orderParms = new Dictionary <string, object>();
                    orderParms.Clear();
                    orderParms.Add("@oldKeyId", txtKeyId.Text);
                    orderParms.Add("@newKeyId", newKeyId);
                    orderParms.Add("@Bill", "17");
                    orderParms.Add("@companyId", CurrentUser.AccountComId);
                    SqlService.ExecuteProcedureCommand("proc_num", orderParms);
                    txtKeyId.Text = newKeyId;

                    //新增日志
                    var billStatus = new LHBillStatus
                    {
                        KeyId       = newKeyId,
                        FCompanyId  = CurrentUser.AccountComId,
                        FActionName = "新增",
                        FDate       = DateTime.Now,
                        FDeptId     = CurrentUser.AccountOrgId,
                        FOperator   = CurrentUser.AccountName,
                        FMemo       = String.Format("单据号{0},{1}新增核销收款单据。", newKeyId, CurrentUser.AccountName)
                    };
                    GasHelper.AddBillStatus(billStatus);
                }

                return(true);
            }

            return(false);
        }