Exemple #1
0
        //提交,只有草稿状态才可以提交
        void SubmitData()
        {
            dgvBillReceivable.EndEdit();
            List <SysSQLString> listSql = new List <SysSQLString>();
            string submit   = ((int)DataSources.EnumAuditStatus.SUBMIT).ToString();   //提交
            string draft    = ((int)DataSources.EnumAuditStatus.DRAFT).ToString();    //草稿
            string notAudit = ((int)DataSources.EnumAuditStatus.NOTAUDIT).ToString(); //审核失败
            string message  = string.Empty;                                           //错误消息

            foreach (DataGridViewRow dgvr in dgvBillReceivable.Rows)
            {
                object isCheck = dgvr.Cells["colCheck"].Value;
                string status  = CommonCtrl.IsNullToString(dgvr.Cells[colOrderStatus.Name].Tag);
                if (isCheck != null && (bool)isCheck && (status == draft || status == notAudit))
                {
                    string order_id     = dgvr.Cells["colPayableSingleID"].Value.ToString();
                    int    strOrderType = Convert.ToInt32(dgvr.Cells[colOrderType.Name].Tag);
                    //应收应付验证单据本次结算金额和明细金额是否一样
                    //if ((orderType == DataSources.EnumOrderType.RECEIVABLE && (DataSources.EnumReceivableType)strOrderType == DataSources.EnumReceivableType.RECEIVABLE) ||
                    //    (orderType == DataSources.EnumOrderType.PAYMENT && (DataSources.EnumPaymentType)strOrderType == DataSources.EnumPaymentType.PAYMENT))
                    //{
                    //if (!DBHelper.IsExist("验证单据和明细金额是否一样", "v_bill_money", string.Format("order_id='{0}'", order_id)))
                    //{
                    //    dgvBillReceivable.CurrentCell = dgvr.Cells[colOrderNum.Name];
                    //    message = "收/付款金额与结算单据实际金额不一致!";
                    //    break;
                    //}
                    //}
                    if (!Financial.CheckTotal(strOrderType, order_id))
                    {
                        dgvBillReceivable.CurrentCell = dgvr.Cells[colOrderNum.Name];
                        message = "收/付款金额与结算单据实际金额不一致!";
                        break;
                    }

                    //应收应付,重新计算已结算/待结算金额(应对同一张结算单,保存多次,再默认页面提交时)
                    if (strOrderType == 1)
                    {
                        if (Financial.CheckDocumentMoney(orderType, order_id))
                        {
                            dgvBillReceivable.CurrentCell = dgvr.Cells[colOrderNum.Name];
                            message = "单据本次结算金额大于待结算金额!";
                            break;
                        }
                        Financial.DocumentMoney(orderType, order_id, listSql);
                    }
                    SysSQLString sql = new SysSQLString();
                    sql.cmdType = CommandType.Text;
                    sql.Param   = new Dictionary <string, string>();
                    sql.Param.Add("submit", submit);
                    sql.Param.Add("draft", draft);
                    sql.Param.Add("notAudit", notAudit);
                    if (orderType == DataSources.EnumOrderType.RECEIVABLE)
                    {
                        sql.Param.Add("order_num", CommonUtility.GetNewNo(DataSources.EnumProjectType.RECEIVABLE));
                    }
                    else
                    {
                        sql.Param.Add("order_num", CommonUtility.GetNewNo(DataSources.EnumProjectType.PAYMENT));
                    }
                    sql.Param.Add("payable_single_id", order_id);
                    sql.sqlString = "update tb_bill_receivable set order_status=@submit,order_num=@order_num where payable_single_id=@payable_single_id and (order_status=@draft or order_status=@notAudit)";
                    listSql.Add(sql);
                    SetDocumentImportStatus("is_lock", DataSources.EnumImportStaus.LOCK, listSql, order_id, dgvr.Cells[colOrderType.Name].Tag.ToString());
                    //如果是应收付,则计算已结算金额
                    if (strOrderType == 1)
                    {
                        Financial.DocumentSettlementByBill(orderType, order_id, listSql);
                    }
                    else if (strOrderType == 0)//预收付,则计算预收付金额
                    {
                        Financial.DocumentAdvanceByBill(orderType, order_id, listSql);
                    }
                }
            }
            if (message.Length > 0)
            {
                MessageBoxEx.ShowError(message);
                return;
            }
            if (listSql.Count == 0)
            {
                MessageBoxEx.Show("请选择要提交的数据!");
                return;
            }
            if (!MessageBoxEx.ShowQuestion("是否要提交选择的数据!"))
            {
                return;
            }
            if (DBHelper.BatchExeSQLStringMultiByTrans("提交应收应付", listSql))
            {
                MessageBoxEx.Show("提交成功!");
                BindData();
            }
            else
            {
                MessageBoxEx.ShowWarning("提交失败!");
            }
        }