示例#1
0
 protected void btnReturn_Click(object sender, System.EventArgs e)
 {
     //返回
     if (Session["Formula"] != null)
     {
         AMSApp.zhenghua.Entity.Formula formula = (AMSApp.zhenghua.Entity.Formula)Session["Formula"];
         this.Response.Redirect("./wfmFormula.aspx?OperFlag=" + Session["OperFlag"].ToString() + "&ProductCode=" + formula.cnvcProductCode);
     }
 }
示例#2
0
        private void UpdatePrice(SqlTransaction trans, Entity.Formula formula, ref DataTable dtDosage, ref DataTable dtFormula)
        {
            DataRow[] drIsMaterial =
                dtDosage.Select("cnvcProductCode='" + formula.cnvcProductCode +
                                "' and cnvcProductType in ('SEMIPRODUCT','FINALPRODUCT')");
            //有半成品

            foreach (DataRow drMaterial in drIsMaterial)
            {
                Dosage         dosage    = new Dosage(drMaterial);
                DataRow[]      drFormula = dtFormula.Select("cnvcProductCode='" + dosage.cnvcCode + "'");
                Entity.Formula formula2  = new AMSApp.zhenghua.Entity.Formula(drFormula[0]);
                UpdatePrice(trans, formula2, ref dtDosage, ref dtFormula);
            }

            //配料全为原材料
            DataRow[] drDosages = dtDosage.Select("cnvcProductCode='" + formula.cnvcProductCode + "'");
            if (drDosages.Length > 0)
            {
                decimal dMaterialCostSum = 0;
                decimal dPackingCostSum  = 0;
                foreach (DataRow drDosage in drDosages)
                {
                    Dosage dosage = new Dosage(drDosage);
                    if (dosage.cnvcProductType == "Pack")
                    {
                        dPackingCostSum += dosage.cnnSum;
                    }
                    else
                    {
                        dMaterialCostSum += dosage.cnnSum;
                    }
                    //dSum += dosage.cnnSum;
                }
                if (dMaterialCostSum != formula.cnnMaterialCostSum || dPackingCostSum != formula.cnnPackingCostSum)
                {
                    formula.cnnMaterialCostSum = dMaterialCostSum;
                    formula.cnnPackingCostSum  = dPackingCostSum;
                    formula.cnnCostSum         = formula.cnnMaterialCostSum + formula.cnnPackingCostSum;
                    SqlHelper.ExecuteNonQuery(trans, CommandType.Text,
                                              "update tbFormula set cnnMaterialCostSum=" + formula.cnnMaterialCostSum +
                                              ",cnnPackingCostSum=" + formula.cnnPackingCostSum + ",cnnCostSum=" +
                                              formula.cnnCostSum + " where cnvcProductCode='" +
                                              formula.cnvcProductCode + "'");
                    DataRow[] drFormula = dtFormula.Select("cnvcProductCode='" + formula.cnvcProductCode + "'");
                    drFormula[0]["cnnMaterialCostSum"] = formula.cnnMaterialCostSum;
                    drFormula[0]["cnnPackingCostSum"]  = formula.cnnPackingCostSum;
                    drFormula[0]["cnnCostSum"]         = formula.cnnCostSum;
                }
                DataRow[] drDosage_Semi = dtDosage.Select("cnvcCode='" + formula.cnvcProductCode + "'");
                foreach (DataRow dr in drDosage_Semi)
                {
                    Dosage  dosage = new Dosage(dr);
                    decimal dPrice = 0;
                    if (formula.cnnPortionCount == 0)
                    {
                        dPrice = formula.cnnCostSum;
                    }
                    else
                    {
                        dPrice = Math.Round(formula.cnnCostSum / formula.cnnPortionCount, 4);
                    }
                    if (dosage.cnnPrice != dPrice)
                    {
                        dosage.cnnPrice = dPrice;
                        dosage.cnnSum   = Math.Round(dosage.cnnPrice * dosage.cnnCount, 4);
                        EntityMapping.Update(dosage, trans);
                        dr["cnnPrice"] = dPrice;//dosage.cnnPrice;
                        dr["cnnSum"]   = dosage.cnnSum;
                    }
                }
            }
        }
示例#3
0
        public void UpdateCost(OperLog operLog)//,BusiLog busiLog)
        {
            using (SqlConnection conn = ConnectionPool.BorrowConnection())
            {
                //conn.Open();

                SqlTransaction trans = conn.BeginTransaction();
                try
                {
                    //tbMaterial
                    DataTable dtMaterial = SingleTableQuery.ExcuteQuery("tbMaterial", trans);
                    DataTable dtDosage   = SingleTableQuery.ExcuteQuery("tbDosage", trans);
                    DataTable dtFormula  = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select cnvcProductType,cnvcProductClass,cnvcProductCode,cnnMaterialCostSum,cnnPackingCostSum,cnnCostSum,cnnPortionCount from tbFormula");
                    //DataRow[] drDosage_Raw_Pack = dtDosage.Select("cnvcProductType<>'SEMIPRODUCT'");
                    //DataRow[] drDosage_Semi = dtDosage.Select("cnvcProductType='SEMIPRODUCT'");
                    //更新原料材料价格
                    foreach (DataRow drDosage in dtDosage.Rows)
                    {
                        Dosage    dosage     = new Dosage(drDosage);
                        DataRow[] drMaterial = dtMaterial.Select("cnvcMaterialCode='" + dosage.cnvcCode + "'");
                        if (drMaterial.Length > 0)
                        {
                            Material material = new Material(drMaterial[0]);
                            if (dosage.cnnPrice != material.cnnPrice)
                            {
                                dosage.cnnPrice = material.cnnPrice;
                                dosage.cnnSum   = Math.Round(dosage.cnnPrice * dosage.cnnCount, 4);
                                EntityMapping.Update(dosage, trans);
                                drDosage["cnnPrice"] = dosage.cnnPrice;
                                drDosage["cnnSum"]   = dosage.cnnSum;
                            }
                        }
                    }
                    foreach (DataRow drFormula in dtFormula.Rows)
                    {
                        Entity.Formula formula = new AMSApp.zhenghua.Entity.Formula(drFormula);
                        if (formula.cnvcProductClass == "")
                        {
                            continue;
                        }
                        UpdatePrice(trans, formula, ref dtDosage, ref dtFormula);
                    }

                    string   strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString();
                    DateTime dtSysTime  = DateTime.Parse(strSysTime);

                    operLog.cndOperDate = dtSysTime;
                    EntityMapping.Create(operLog, trans);
                    //EntityMapping.Create(busiLog, trans);
                    trans.Commit();
                }
                catch (SqlException sex)
                {
                    trans.Rollback();
                    LogAdapter.WriteDatabaseException(sex);
                    throw sex;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    LogAdapter.WriteFeaturesException(ex);
                    throw ex;
                }
                finally
                {
                    ConnectionPool.ReturnConnection(conn);
                }
            }
        }