Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sErr   = "";
            int    iCount = 0;

            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }


                SqlConnection conn = new SqlConnection(Conn);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    int iRowCou = 0;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool bChoose = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbChoose));
                        if (!bChoose)
                        {
                            continue;
                        }

                        decimal dQty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOrderQty));
                        if (dQty <= 0)
                        {
                            continue;
                        }

                        DateTime dDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColPlanDate));
                        if (dNowDate > dDate)
                        {
                            dDate = dNowDate;
                        }
                        iRowCou += 1;
                    }

                    if (sErr.Length > 0)
                    {
                        throw new Exception(sErr);
                    }

                    sSQL = @"
declare @p5 int
set @p5=1000000003
declare @p6 int
set @p6=1000000005
exec sp_getID N'00',N'111111',N'Pomain',222222,@p5 output,@p6 output
select @p5, @p6
";

                    sSQL = sSQL.Replace("111111", sAccID);
                    sSQL = sSQL.Replace("222222", iRowCou.ToString());
                    DataTable dt         = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    long      iID        = BaseFunction.ReturnLong(dt.Rows[0][0]);
                    long      iIDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]);
                    iIDDetails = iIDDetails - iRowCou;

                    sSQL = @"
select isnull(max(cNumber),0) as Maxnumber From VoucherHistory  with (NOLOCK) Where CardNumber = '88' and cContent like '%单据日期|采购类型%' and cSeed = 'aaaaaaaa'
";
                    sSQL = sSQL.Replace("aaaaaaaa", BaseFunction.ReturnDate(sLogDate).ToString("yyyy") + "1");
                    DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    long iVouch = 0;
                    dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        iVouch = 0;
                    }
                    else
                    {
                        iVouch = BaseFunction.ReturnLong(dt.Rows[0][0]);
                    }

                    iVouch += 1;

                    Model.PO_Pomain model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.PO_Pomain();


                    sSQL = "select * from PurchaseType where isnull(bDefault,0) = 1";
                    DataTable dtCodeType = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtCodeType == null || dtCodeType.Rows.Count < 1)
                    {
                        throw new Exception("Please set purchase category");
                    }

                    model.cPTCode = dtCodeType.Rows[0]["cPTCode"].ToString().Trim();

                    model.cPOID   = sGetVouCode(BaseFunction.ReturnDate(sLogDate).ToString("yyyy"), iVouch, model.cPTCode);
                    model.dPODate = BaseFunction.ReturnDate(sLogDate);

                    sSQL = "select * from Vendor where cVenCode = '" + gridView1.GetRowCellValue(0, gridColcVenCode).ToString().Trim() + "' or cVenName = '" + gridView1.GetRowCellValue(0, gridColcVenCode).ToString().Trim() + "' or cVenAbbName = '" + gridView1.GetRowCellValue(0, gridColcVenCode).ToString().Trim() + "'";
                    DataTable dtVendor = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dtVendor == null || dtVendor.Rows.Count == 0)
                    {
                        throw new Exception("Vendor error");
                    }
                    model.cVenCode = dtVendor.Rows[0]["cVenCode"].ToString().Trim();

                    if (dtVendor.Rows[0]["cVenDepart"].ToString().Trim() == "")
                    {
                        throw new Exception("Vendor Department error");
                    }
                    model.cDepCode = dtVendor.Rows[0]["cVenDepart"].ToString().Trim();

                    if (dtVendor.Rows[0]["cVenPPerson"].ToString().Trim() != "")
                    {
                        model.cPersonCode = dtVendor.Rows[0]["cVenPPerson"].ToString().Trim();
                    }

                    if (dtVendor.Rows[0]["cVenExch_name"].ToString().Trim() == "")
                    {
                        model.cexch_name = "SGD";
                    }
                    else
                    {
                        model.cexch_name = dtVendor.Rows[0]["cVenExch_name"].ToString().Trim();
                    }
                    model.nflat = BaseFunction.ReturnDecimal(txtnflat.Text.Trim());

                    decimal dTax = BaseFunction.ReturnDecimal(dtVendor.Rows[0]["iVenTaxRate"]);
                    //if (dTax > 0)
                    //{ }
                    //else
                    //{
                    model.iTaxRate = dTax;
                    //}
                    model.iCost            = 0;
                    model.iBargain         = 0;
                    model.cMaker           = sUserName;
                    model.POID             = iID;
                    model.iVTid            = 8173;
                    model.cBusType         = "普通采购";
                    model.iDiscountTaxType = 0;
                    model.IsWfControlled   = false;
                    model.cmaketime        = dNow;
                    model.iPrintCount      = 0;
                    //model.cVerifier = sUserName;
                    //model.iverifystateex = 2;
                    //model.cAuditDate = dNowDate;
                    //model.cAuditTime = dNow;

                    model.cState         = 0;   //审核后是1
                    model.iverifystateex = 0;

                    DAL.PO_Pomain dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.PO_Pomain();
                    sSQL = dal.Add(model);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = @"
if exists(select * From VoucherHistory  with (NOLOCK) Where CardNumber = '88' and cContent like '%单据日期%' and cSeed = N'aaaaaaaa')
    update VoucherHistory set cNumber = bbbbbbbb Where  CardNumber=N'88' and cContent like '%单据日期%' and cSeed = N'aaaaaaaa'
else
    insert into VoucherHistory(CardNumber,  cContent, cContentRule, cSeed, cNumber, bEmpty)
    values(N'88',N'单据日期|采购类型',N'YYYY|',N'aaaaaaaa',bbbbbbbb,0)
";
                    sSQL = sSQL.Replace("aaaaaaaa", BaseFunction.ReturnDate(sLogDate).ToString("yyyy") + "1");
                    sSQL = sSQL.Replace("bbbbbbbb", iVouch.ToString());

                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    int iRowNo = 0;
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        bool bChoose = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColbChoose));
                        if (!bChoose)
                        {
                            continue;
                        }

                        decimal dQty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOrderQty));
                        if (dQty <= 0)
                        {
                            continue;
                        }

                        sSQL = "select * from Inventory where cInvCode = '" + gridView1.GetRowCellDisplayText(i, gridColcInvCode).ToString().Trim() + "'";
                        DataTable dtInv = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                        iIDDetails += 1;

                        Model.PO_Podetails models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.PO_Podetails();
                        models.ID        = iIDDetails;
                        models.cInvCode  = gridView1.GetRowCellDisplayText(i, gridColcInvCode).ToString().Trim();
                        models.iQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOrderQty));
                        decimal dNum = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOrderNum));
                        if (dNum != 0)
                        {
                            models.iNum = dNum;
                        }
                        models.cDefine26 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColvolume));
                        models.cDefine27 = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColweight));

                        decimal dPrice = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice));
                        if (dPrice == 0)
                        {
                            throw new Exception("Row " + (i + 1).ToString() + " please set vendor price");
                        }

                        //decimal dTaxRate = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColTaxRate));
                        //if(dTaxRate == 0)
                        //    dTaxRate = 7;
                        models.iPerTaxRate = model.iTaxRate;
                        models.iUnitPrice  = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrice));
                        models.iMoney      = BaseFunction.ReturnDecimal(models.iUnitPrice * models.iQuantity, 6);
                        models.iTaxPrice   = BaseFunction.ReturnDecimal(models.iUnitPrice * (1 + models.iPerTaxRate / 100));
                        models.iSum        = BaseFunction.ReturnDecimal(models.iTaxPrice * models.iQuantity, 6);
                        models.iTax        = models.iSum - models.iMoney;

                        decimal iFlat = BaseFunction.ReturnDecimal(txtnflat.Text.Trim());

                        if (iFlat == 1)
                        {
                            models.iNatUnitPrice = models.iUnitPrice;
                        }
                        else
                        {
                            if (radio2.Checked)
                            {
                                models.iNatUnitPrice = BaseFunction.ReturnDecimal(models.iUnitPrice / iFlat);
                            }
                            if (radio1.Checked)
                            {
                                models.iNatUnitPrice = BaseFunction.ReturnDecimal(models.iUnitPrice * iFlat);
                            }
                        }
                        models.iNatMoney = BaseFunction.ReturnDecimal(models.iNatUnitPrice * models.iQuantity, 6);
                        models.iNatSum   = BaseFunction.ReturnDecimal(models.iNatMoney * (1 + models.iPerTaxRate / 100));
                        models.iNatTax   = models.iNatSum - models.iNatMoney;


                        models.dArriveDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColPlanDate));


                        models.bGsp     = 0;
                        models.POID     = iID;
                        models.cUnitID  = gridView1.GetRowCellValue(i, gridColcComunitCode).ToString().Trim();
                        models.bTaxCost = true;

                        iRowNo += 1;
                        //models.irowno = iRowNo;
                        models.ivouchrowno = iRowNo;

                        DAL.PO_Podetails dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.PO_Podetails();
                        sSQL   = dals.Add(models);
                        iCount = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                        sSQL = "update PO_Pomain set iTaxrate = " + models.iPerTaxRate.ToString() + " where poid = " + iID.ToString();
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }


                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("OK\n" + model.cPOID);
                        gridControl1.DataSource = null;
                    }
                    else
                    {
                        throw new Exception("no data");
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();
                    throw new Exception(ee.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model.PO_Pomain model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.cPOID != null)
            {
                strSql1.Append("cPOID,");
                strSql2.Append("'" + model.cPOID + "',");
            }
            if (model.dPODate != null)
            {
                strSql1.Append("dPODate,");
                strSql2.Append("'" + model.dPODate + "',");
            }
            if (model.cVenCode != null)
            {
                strSql1.Append("cVenCode,");
                strSql2.Append("'" + model.cVenCode + "',");
            }
            if (model.cDepCode != null)
            {
                strSql1.Append("cDepCode,");
                strSql2.Append("'" + model.cDepCode + "',");
            }
            if (model.cPersonCode != null)
            {
                strSql1.Append("cPersonCode,");
                strSql2.Append("'" + model.cPersonCode + "',");
            }
            if (model.cPTCode != null)
            {
                strSql1.Append("cPTCode,");
                strSql2.Append("'" + model.cPTCode + "',");
            }
            if (model.cArrivalPlace != null)
            {
                strSql1.Append("cArrivalPlace,");
                strSql2.Append("'" + model.cArrivalPlace + "',");
            }
            if (model.cSCCode != null)
            {
                strSql1.Append("cSCCode,");
                strSql2.Append("'" + model.cSCCode + "',");
            }
            if (model.cexch_name != null)
            {
                strSql1.Append("cexch_name,");
                strSql2.Append("'" + model.cexch_name + "',");
            }
            if (model.nflat != null)
            {
                strSql1.Append("nflat,");
                strSql2.Append("" + model.nflat + ",");
            }
            if (model.iTaxRate != null)
            {
                strSql1.Append("iTaxRate,");
                strSql2.Append("" + model.iTaxRate + ",");
            }
            if (model.cPayCode != null)
            {
                strSql1.Append("cPayCode,");
                strSql2.Append("'" + model.cPayCode + "',");
            }
            if (model.iCost != null)
            {
                strSql1.Append("iCost,");
                strSql2.Append("" + model.iCost + ",");
            }
            if (model.iBargain != null)
            {
                strSql1.Append("iBargain,");
                strSql2.Append("" + model.iBargain + ",");
            }
            if (model.cMemo != null)
            {
                strSql1.Append("cMemo,");
                strSql2.Append("'" + model.cMemo + "',");
            }
            if (model.cState != null)
            {
                strSql1.Append("cState,");
                strSql2.Append("" + model.cState + ",");
            }
            if (model.cPeriod != null)
            {
                strSql1.Append("cPeriod,");
                strSql2.Append("'" + model.cPeriod + "',");
            }
            if (model.cMaker != null)
            {
                strSql1.Append("cMaker,");
                strSql2.Append("'" + model.cMaker + "',");
            }
            if (model.cVerifier != null)
            {
                strSql1.Append("cVerifier,");
                strSql2.Append("'" + model.cVerifier + "',");
            }
            if (model.cCloser != null)
            {
                strSql1.Append("cCloser,");
                strSql2.Append("'" + model.cCloser + "',");
            }
            if (model.cDefine1 != null)
            {
                strSql1.Append("cDefine1,");
                strSql2.Append("'" + model.cDefine1 + "',");
            }
            if (model.cDefine2 != null)
            {
                strSql1.Append("cDefine2,");
                strSql2.Append("'" + model.cDefine2 + "',");
            }
            if (model.cDefine3 != null)
            {
                strSql1.Append("cDefine3,");
                strSql2.Append("'" + model.cDefine3 + "',");
            }
            if (model.cDefine4 != null)
            {
                strSql1.Append("cDefine4,");
                strSql2.Append("'" + model.cDefine4 + "',");
            }
            if (model.cDefine5 != null)
            {
                strSql1.Append("cDefine5,");
                strSql2.Append("" + model.cDefine5 + ",");
            }
            if (model.cDefine6 != null)
            {
                strSql1.Append("cDefine6,");
                strSql2.Append("'" + model.cDefine6 + "',");
            }
            if (model.cDefine7 != null)
            {
                strSql1.Append("cDefine7,");
                strSql2.Append("" + model.cDefine7 + ",");
            }
            if (model.cDefine8 != null)
            {
                strSql1.Append("cDefine8,");
                strSql2.Append("'" + model.cDefine8 + "',");
            }
            if (model.cDefine9 != null)
            {
                strSql1.Append("cDefine9,");
                strSql2.Append("'" + model.cDefine9 + "',");
            }
            if (model.cDefine10 != null)
            {
                strSql1.Append("cDefine10,");
                strSql2.Append("'" + model.cDefine10 + "',");
            }
            if (model.POID != null)
            {
                strSql1.Append("POID,");
                strSql2.Append("" + model.POID + ",");
            }
            if (model.iVTid != null)
            {
                strSql1.Append("iVTid,");
                strSql2.Append("" + model.iVTid + ",");
            }
            //if (model.ufts != null)
            //{
            //    strSql1.Append("ufts,");
            //    strSql2.Append("" + model.ufts + ",");
            //}
            if (model.cChanger != null)
            {
                strSql1.Append("cChanger,");
                strSql2.Append("'" + model.cChanger + "',");
            }
            if (model.cBusType != null)
            {
                strSql1.Append("cBusType,");
                strSql2.Append("'" + model.cBusType + "',");
            }
            if (model.cDefine11 != null)
            {
                strSql1.Append("cDefine11,");
                strSql2.Append("'" + model.cDefine11 + "',");
            }
            if (model.cDefine12 != null)
            {
                strSql1.Append("cDefine12,");
                strSql2.Append("'" + model.cDefine12 + "',");
            }
            if (model.cDefine13 != null)
            {
                strSql1.Append("cDefine13,");
                strSql2.Append("'" + model.cDefine13 + "',");
            }
            if (model.cDefine14 != null)
            {
                strSql1.Append("cDefine14,");
                strSql2.Append("'" + model.cDefine14 + "',");
            }
            if (model.cDefine15 != null)
            {
                strSql1.Append("cDefine15,");
                strSql2.Append("" + model.cDefine15 + ",");
            }
            if (model.cDefine16 != null)
            {
                strSql1.Append("cDefine16,");
                strSql2.Append("" + model.cDefine16 + ",");
            }
            if (model.cLocker != null)
            {
                strSql1.Append("cLocker,");
                strSql2.Append("'" + model.cLocker + "',");
            }
            if (model.iDiscountTaxType != null)
            {
                strSql1.Append("iDiscountTaxType,");
                strSql2.Append("" + model.iDiscountTaxType + ",");
            }
            if (model.iverifystateex != null)
            {
                strSql1.Append("iverifystateex,");
                strSql2.Append("" + model.iverifystateex + ",");
            }
            if (model.ireturncount != null)
            {
                strSql1.Append("ireturncount,");
                strSql2.Append("" + model.ireturncount + ",");
            }
            if (model.IsWfControlled != null)
            {
                strSql1.Append("IsWfControlled,");
                strSql2.Append("" + (model.IsWfControlled ? 1 : 0) + ",");
            }
            if (model.cmaketime != null)
            {
                strSql1.Append("cmaketime,");
                strSql2.Append("'" + model.cmaketime + "',");
            }
            if (model.cModifyTime != null)
            {
                strSql1.Append("cModifyTime,");
                strSql2.Append("'" + model.cModifyTime + "',");
            }
            if (model.cAuditTime != null)
            {
                strSql1.Append("cAuditTime,");
                strSql2.Append("'" + model.cAuditTime + "',");
            }
            if (model.cAuditDate != null)
            {
                strSql1.Append("cAuditDate,");
                strSql2.Append("'" + model.cAuditDate + "',");
            }
            if (model.cModifyDate != null)
            {
                strSql1.Append("cModifyDate,");
                strSql2.Append("'" + model.cModifyDate + "',");
            }
            if (model.cReviser != null)
            {
                strSql1.Append("cReviser,");
                strSql2.Append("'" + model.cReviser + "',");
            }
            if (model.cVenPUOMProtocol != null)
            {
                strSql1.Append("cVenPUOMProtocol,");
                strSql2.Append("'" + model.cVenPUOMProtocol + "',");
            }
            if (model.cChangVerifier != null)
            {
                strSql1.Append("cChangVerifier,");
                strSql2.Append("'" + model.cChangVerifier + "',");
            }
            if (model.cChangAuditTime != null)
            {
                strSql1.Append("cChangAuditTime,");
                strSql2.Append("'" + model.cChangAuditTime + "',");
            }
            if (model.cChangAuditDate != null)
            {
                strSql1.Append("cChangAuditDate,");
                strSql2.Append("'" + model.cChangAuditDate + "',");
            }
            if (model.iBG_OverFlag != null)
            {
                strSql1.Append("iBG_OverFlag,");
                strSql2.Append("" + model.iBG_OverFlag + ",");
            }
            if (model.cBG_Auditor != null)
            {
                strSql1.Append("cBG_Auditor,");
                strSql2.Append("'" + model.cBG_Auditor + "',");
            }
            if (model.cBG_AuditTime != null)
            {
                strSql1.Append("cBG_AuditTime,");
                strSql2.Append("'" + model.cBG_AuditTime + "',");
            }
            if (model.ControlResult != null)
            {
                strSql1.Append("ControlResult,");
                strSql2.Append("" + model.ControlResult + ",");
            }
            if (model.iflowid != null)
            {
                strSql1.Append("iflowid,");
                strSql2.Append("" + model.iflowid + ",");
            }
            if (model.iPrintCount != null)
            {
                strSql1.Append("iPrintCount,");
                strSql2.Append("" + model.iPrintCount + ",");
            }
            if (model.dCloseDate != null)
            {
                strSql1.Append("dCloseDate,");
                strSql2.Append("'" + model.dCloseDate + "',");
            }
            if (model.dCloseTime != null)
            {
                strSql1.Append("dCloseTime,");
                strSql2.Append("'" + model.dCloseTime + "',");
            }
            if (model.ccleanver != null)
            {
                strSql1.Append("ccleanver,");
                strSql2.Append("'" + model.ccleanver + "',");
            }
            if (model.cContactCode != null)
            {
                strSql1.Append("cContactCode,");
                strSql2.Append("'" + model.cContactCode + "',");
            }
            if (model.cVenPerson != null)
            {
                strSql1.Append("cVenPerson,");
                strSql2.Append("'" + model.cVenPerson + "',");
            }
            if (model.cVenBank != null)
            {
                strSql1.Append("cVenBank,");
                strSql2.Append("'" + model.cVenBank + "',");
            }
            if (model.cVenAccount != null)
            {
                strSql1.Append("cVenAccount,");
                strSql2.Append("'" + model.cVenAccount + "',");
            }
            if (model.cappcode != null)
            {
                strSql1.Append("cappcode,");
                strSql2.Append("'" + model.cappcode + "',");
            }
            if (model.csysbarcode != null)
            {
                strSql1.Append("csysbarcode,");
                strSql2.Append("'" + model.csysbarcode + "',");
            }
            if (model.cCurrentAuditor != null)
            {
                strSql1.Append("cCurrentAuditor,");
                strSql2.Append("'" + model.cCurrentAuditor + "',");
            }
            strSql.Append("insert into PO_Pomain(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return(strSql.ToString());
        }