Ejemplo n.º 1
0
 public static int InsertCostProductionInfo(ProcutionCostModel model, ArrayList Detailsmodels)
 {
     if (model == null || Detailsmodels == null)
     {
         return(0);
     }
     try
     {
         return(CostProductionDBHelper.InsertCostProductionInfo(model, Detailsmodels));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 2
0
        public static int InsertCostProductionInfo(ProcutionCostModel model, ArrayList Detailsmodels)
        {
            SqlConnection conn = new SqlConnection(SqlHelper._connectionStringStr);

            conn.Open();
            SqlTransaction mytran = conn.BeginTransaction();

            try
            {
                StringBuilder cmdsql = new StringBuilder();
                cmdsql.AppendLine("Insert into officedba.CostProduction");
                cmdsql.AppendLine("(CompanyCD,PeriodNum,ProductID,AccountMethod,");
                cmdsql.AppendLine("CompRatePro,IsInvestment,FinishedProductCount,");
                cmdsql.AppendLine("InProuctCount,MaterialsUnit,WageUnit,OverheadUnit,");
                cmdsql.AppendLine("BurningPowerUnit,CurrentMonthMaterials,CurrentMonthHours,");
                cmdsql.AppendLine("EndMonthHours,EndMonthMaterials,CurrencyType,CurrencyRate,Remark)");
                cmdsql.AppendLine("values(@CompanyCD,@PeriodNum,@ProductID,@AccountMethod,");
                cmdsql.AppendLine("@CompRatePro,@IsInvestment,@FinishedProductCount,");
                cmdsql.AppendLine("@InProuctCount,@MaterialsUnit,@WageUnit,@OverheadUnit,");
                cmdsql.AppendLine("@BurningPowerUnit,@CurrentMonthMaterials,@CurrentMonthHours,");
                cmdsql.AppendLine("@EndMonthHours,@EndMonthMaterials,@CurrencyType,@CurrencyRate,@Remark)");
                cmdsql.AppendLine("set @IntID= @@IDENTITY");
                SqlParameter[] parms =
                {
                    new SqlParameter("@CompanyCD",             SqlDbType.VarChar,    8),
                    new SqlParameter("@PeriodNum",             SqlDbType.VarChar,    8),
                    new SqlParameter("@ProductID",             SqlDbType.Int),
                    new SqlParameter("@AccountMethod",         SqlDbType.Char),
                    new SqlParameter("@CompRatePro",           SqlDbType.Decimal),
                    new SqlParameter("@IsInvestment",          SqlDbType.Char),
                    new SqlParameter("@FinishedProductCount",  SqlDbType.Decimal),
                    new SqlParameter("@InProuctCount",         SqlDbType.Decimal),
                    new SqlParameter("@MaterialsUnit",         SqlDbType.Decimal),
                    new SqlParameter("@WageUnit",              SqlDbType.Decimal),
                    new SqlParameter("@OverheadUnit",          SqlDbType.Decimal),
                    new SqlParameter("@BurningPowerUnit",      SqlDbType.Decimal),
                    new SqlParameter("@CurrentMonthMaterials", SqlDbType.Decimal),
                    new SqlParameter("@CurrentMonthHours",     SqlDbType.Decimal),
                    new SqlParameter("@EndMonthHours",         SqlDbType.Decimal),
                    new SqlParameter("@EndMonthMaterials",     SqlDbType.Decimal),
                    new SqlParameter("@CurrencyType",          SqlDbType.Int),
                    new SqlParameter("@CurrencyRate",          SqlDbType.Decimal),
                    new SqlParameter("@Remark",                SqlDbType.VarChar,  200),
                    new SqlParameter("@IntID",                 SqlDbType.Int)
                };
                parms[0].Value  = model.CompanyCD;
                parms[1].Value  = model.PeriodNum;
                parms[2].Value  = model.ProductID;
                parms[3].Value  = model.AccountMethod;
                parms[4].Value  = model.CompRatePro;
                parms[5].Value  = model.IsInvestment;
                parms[6].Value  = model.FinishedProductCount;
                parms[7].Value  = model.InProuctCount;
                parms[8].Value  = model.MaterialsUnit;
                parms[9].Value  = model.WageUnit;
                parms[10].Value = model.OverheadUnit;
                parms[11].Value = model.BurningPowerUnit;
                parms[12].Value = model.CurrentMonthMaterials;
                parms[13].Value = model.CurrentMonthHours;
                parms[14].Value = model.EndMonthHours;
                parms[15].Value = model.EndMonthMaterials;
                parms[16].Value = model.CurrencyType;
                parms[17].Value = model.CurrencyRate;
                parms[18].Value = model.Remark;
                parms[19]       = SqlHelper.GetOutputParameter("@IntID", SqlDbType.Int);
                int rev = SqlHelper.ExecuteNonQuery(mytran, CommandType.Text, cmdsql.ToString(), parms);
                int ID  = Convert.ToInt32(parms[19].Value);
                if (ID > 0)
                {
                    StringBuilder sql = new StringBuilder();
                    sql.AppendLine("Insert into officedba.CostDetails");
                    sql.AppendLine("(CTID,ItemName,Materials,Wage,");
                    sql.AppendLine("Overhead,BurningPower,TotalCost)");
                    sql.AppendLine("values(@CTID,@ItemName,@Materials,@Wage,");
                    sql.AppendLine("@Overhead,@BurningPower,@TotalCost)");

                    SqlParameter[] paras =
                    {
                        new SqlParameter("@CTID",         SqlDbType.Int),
                        new SqlParameter("@ItemName",     SqlDbType.VarChar,  50),
                        new SqlParameter("@Materials",    SqlDbType.Decimal),
                        new SqlParameter("@Wage",         SqlDbType.Decimal),
                        new SqlParameter("@Overhead",     SqlDbType.Decimal),
                        new SqlParameter("@BurningPower", SqlDbType.Decimal),
                        new SqlParameter("@TotalCost",    SqlDbType.Decimal)
                    };

                    foreach (CostDetailsModel mdl in Detailsmodels)
                    {
                        paras[0].Value = ID;
                        paras[1].Value = mdl.ItemName;
                        paras[2].Value = mdl.Materials;
                        paras[3].Value = mdl.Wage;
                        paras[4].Value = mdl.Overhead;
                        paras[5].Value = mdl.BurningPower;
                        paras[6].Value = mdl.TotalCost;

                        SqlHelper.ExecuteNonQuery(mytran, CommandType.Text, sql.ToString(), paras);
                    }
                }
                mytran.Commit();
                return(ID);
            }
            catch (Exception ex)
            {
                mytran.Rollback();
                throw ex;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }