コード例 #1
0
 public RulesForm(Entity.AraSystem sysetm) : this()
 {
     this.sysetm      = sysetm;
     resultFormula    = new Entity.Formula();
     conditionFormula = new Entity.Formula();
     displayData();
     activateForm(false);
 }
コード例 #2
0
        private void activateForm(bool b)
        {
            actionsCmb.Enabled = agentsCmb.Enabled = effectsCmb.Enabled = b;
            resultFormula      = new Entity.Formula();
            conditionFormula   = new Entity.Formula();

            saveBtn.Enabled = cancelBtn.Enabled = b;
            newBtn.Enabled  = !b;
        }
コード例 #3
0
 private void clearForm()
 {
     actionsCmb.SelectedIndex                 = -1;
     agentsCmb.SelectedIndex                  = -1;
     formulaFluentsCmb.SelectedIndex          = -1;
     conditionFormulaFluentsCmb.SelectedIndex = -1;
     effectsCmb.SelectedItem                  = null;
     conditionFormulaTB.Text                  = "";
     formulaTB.Text   = "";
     resultFormula    = new Entity.Formula();
     conditionFormula = new Entity.Formula();
 }
コード例 #4
0
        public QueriesForm()
        {
            InitializeComponent();
            items = Entity.AraSystem.GetInstance().States;
            G     = new Graph("Graph");
            DrawGraph();
            query                        = new Entity.Query();
            resultFormula                = new Formula();
            resultStatus                 = new Hashtable();
            actionsCmb.DataSource        = Entity.AraSystem.GetInstance().Actions.ToArray();
            agentsCmb.DataSource         = Entity.AraSystem.GetInstance().Agents.ToArray();
            formulaFluentsCmb.DataSource = Entity.AraSystem.GetInstance().Fluents.ToList();

            actionsCmb.SelectedIndex = -1;
            agentsCmb.SelectedIndex  = -1;
        }
コード例 #5
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;
                    }
                }
            }
        }
コード例 #6
0
        public void UpdateFormula(Entity.Formula formula, DataTable dtDosage, DataTable dtPacking, DataTable dtOperStandard, OperLog operLog)
        {
            using (SqlConnection conn = ConnectionPool.BorrowConnection())
            {
                //conn.Open();

                SqlTransaction trans = conn.BeginTransaction();
                try
                {
                    Entity.Formula fold = EntityMapping.Get(formula, trans) as Entity.Formula;
                    if (fold == null)
                    {
                        throw new Exception("未找到配方");
                    }
                    fold.SynchronizeModifyValue(formula);
                    fold.IsUse = formula.IsUse;
                    EntityMapping.Update(fold, trans);

                    DataTable dtGoods =
                        SqlHelper.ExecuteDataTable(trans, CommandType.Text,
                                                   "select * from tbGoods where vcGoodsID='" + formula.cnvcProductCode + "'");
                    if (dtGoods.Rows.Count == 1 && formula.cnvcProductType == "FINALPRODUCT")
                    {
                        Goods goods = new Goods(dtGoods.Rows[0]);

                        //goods.vcGoodsID = formula.cnvcProductCode;
                        if (goods.vcGoodsName != formula.cnvcProductName)
                        {
                            goods.vcSpell = Helper.GetChineseSpell(formula.cnvcProductName);
                        }
                        goods.vcGoodsName = formula.cnvcProductName;
                        goods.vcComments  = formula.IsUse ? "1" : "0";
                        EntityMapping.Update(goods, trans);
                    }

                    DataTable dtHavedDosage       = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select * from tbDosage where cnvcProductCode='" + formula.cnvcProductCode + "'");
                    DataTable dtHavedOperStandard =
                        SqlHelper.ExecuteDataTable(trans, CommandType.Text,
                                                   "select * from tbOperStandard where cnvcProductCode='" + formula.cnvcProductCode + "'");
                    //有的更新,没的添加
                    foreach (DataRow drDosage in dtDosage.Rows)
                    {
                        Dosage    newdosage = new Dosage(drDosage);
                        DataRow[] dr        = dtHavedDosage.Select("cnvcCode='" + newdosage.cnvcCode + "'");
                        if (dr.Length > 0)
                        {
                            Dosage dosage = new Dosage(dr[0]);
                            dosage.cnnCount = newdosage.cnnCount;
                            dosage.cnnSum   = newdosage.cnnSum;
                            EntityMapping.Update(dosage, trans);
                        }
                        else
                        {
                            EntityMapping.Create(newdosage, trans);
                        }
                    }

                    foreach (DataRow drPacking in dtPacking.Rows)
                    {
                        Dosage    newdosage = new Dosage(drPacking);
                        DataRow[] dr        = dtHavedDosage.Select("cnvcCode='" + newdosage.cnvcCode + "'");
                        if (dr.Length > 0)
                        {
                            Dosage dosage = new Dosage(dr[0]);
                            dosage.cnnCount = newdosage.cnnCount;
                            dosage.cnnSum   = newdosage.cnnSum;
                            EntityMapping.Update(dosage, trans);
                        }
                        else
                        {
                            EntityMapping.Create(newdosage, trans);
                        }
                    }
                    foreach (DataRow drDosage in dtHavedDosage.Rows)
                    {
                        Dosage dosage = new Dosage(drDosage);
                        if (dosage.cnvcProductType == "Pack")
                        {
                            DataRow[] dr = dtPacking.Select("cnvcCode='" + dosage.cnvcCode + "'");
                            if (dr.Length == 0)
                            {
                                EntityMapping.Delete(dosage, trans);
                            }
                        }
                        else
                        {
                            DataRow[] dr = dtDosage.Select("cnvcCode='" + dosage.cnvcCode + "'");
                            if (dr.Length == 0)
                            {
                                EntityMapping.Delete(dosage, trans);
                            }
                        }
                    }
                    foreach (DataRow drOperStandard in dtOperStandard.Rows)
                    {
                        OperStandard newoperStandard = new OperStandard(drOperStandard);
                        DataRow[]    dr = dtHavedOperStandard.Select("cnnSort=" + newoperStandard.cnnSort.ToString());
                        if (dr.Length > 0)
                        {
                            OperStandard operStandard = new OperStandard(dr[0]);
                            operStandard.cnvcKey      = newoperStandard.cnvcKey;
                            operStandard.cnvcStandard = newoperStandard.cnvcStandard;
                            EntityMapping.Update(operStandard, trans);
                        }
                        else
                        {
                            EntityMapping.Create(newoperStandard, trans);
                        }
                    }
                    foreach (DataRow drOperStandard in dtHavedOperStandard.Rows)
                    {
                        OperStandard operStandard = new OperStandard(drOperStandard);
                        DataRow[]    dr           = dtOperStandard.Select("cnnSort=" + operStandard.cnnSort.ToString());
                        if (dr.Length == 0)
                        {
                            EntityMapping.Delete(operStandard, trans);
                        }
                    }
                    string   strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString();
                    DateTime dtSysTime  = DateTime.Parse(strSysTime);

                    operLog.cndOperDate  = dtSysTime;
                    operLog.cnvcComments = "配方编码:" + formula.cnvcProductCode;
                    EntityMapping.Create(operLog, 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);
                }
            }
        }
コード例 #7
0
        public void AddFormula(Entity.Formula formula, DataTable dtDosage, DataTable dtPacking, DataTable dtOperStandard, OperLog operLog)
        {
            using (SqlConnection conn = ConnectionPool.BorrowConnection())
            {
                //conn.Open();

                SqlTransaction trans = conn.BeginTransaction();
                try
                {
                    formula.cnvcPortionUnit = "份";
                    EntityMapping.Create(formula, trans);
                    DataTable dtGoods =
                        SqlHelper.ExecuteDataTable(trans, CommandType.Text,
                                                   "select * from tbGoods where vcGoodsID='" + formula.cnvcProductCode + "'");
                    if (dtGoods.Rows.Count == 0 && formula.cnvcProductType == "FINALPRODUCT")
                    {
                        Goods goods = new Goods();
                        goods.vcGoodsID   = formula.cnvcProductCode;
                        goods.vcGoodsName = formula.cnvcProductName;
                        goods.vcSpell     = Helper.GetChineseSpell(formula.cnvcProductName);
                        goods.iIgValue    = -1;
                        goods.vcComments  = formula.IsUse ? "1" : "0";
                        EntityMapping.Create(goods, trans);
                    }
                    foreach (DataRow drDosage in dtDosage.Rows)
                    {
                        Dosage dosage = new Dosage(drDosage);
                        EntityMapping.Create(dosage, trans);
                    }
                    foreach (DataRow drPacking in dtPacking.Rows)
                    {
                        Dosage dosage = new Dosage(drPacking);
                        EntityMapping.Create(dosage, trans);
                    }
                    foreach (DataRow drOperStandard in dtOperStandard.Rows)
                    {
                        OperStandard operStandard = new OperStandard(drOperStandard);
                        EntityMapping.Create(operStandard, trans);
                    }

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

                    operLog.cndOperDate  = dtSysTime;
                    operLog.cnvcComments = "配方编码:" + formula.cnvcProductCode;
                    EntityMapping.Create(operLog, 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);
                }
            }
        }