/*************************************************************
         * 修正ボタン押下時の処理
         *************************************************************/
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("更新しますか?") == DialogResult.Yes)
            {
                using (var context = new CostAccountingEntities())
                {
                    var target = from t in context.Machine
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.code.Equals(textRegCode.Text)
                                 select t;

                    if (target.Count() > 0)
                    {
                        target.First().code = textRegCode.Text;
                        target.First().name = textRegName.Text;
                        target.First().rate_budget = Conversion.Parse(textRegRateBudget.Text);
                        target.First().rate_actual = Conversion.Parse(textRegRateActual.Text);
                        target.First().note = textRegNote.Text;
                        target.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                        target.First().update_date = DateTime.Now;
                    }
                    context.SaveChanges();
                }

                Logger.Info(Message.INF004, new string[] { this.Text, Message.create(textRegCode, textRegName) });
                Program.MessageBoxAfter("更新しました。");
                Form_Prepare_MachineReg_Load(sender, e);
            }
        }
        /*************************************************************
         * 修正ボタン押下時の処理
         *************************************************************/
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("更新しますか?") == DialogResult.Yes)
            {
                using (var context = new CostAccountingEntities())
                {
                    var target = from t in context.ProductCode
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.code.Equals(textRegCode.Text)
                                 select t;

                    if (target.Count() > 0)
                    {
                        target.First().code = textRegCode.Text;
                        target.First().name = textRegName.Text;
                        target.First().unit = textRegUnit.Text;
                        target.First().kbn = getProductKbn(groupKbn1);
                        target.First().note = textRegNote.Text;
                        target.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                        target.First().update_date = DateTime.Now;
                    }
                    context.SaveChanges();
                }

                Logger.Info(Message.INF004, new string[] { this.Text, Message.create(textRegCode, textRegName) });
                Program.MessageBoxAfter("更新し、再検索を行いました。");
                btnSearch_Click(sender, e);
            }
        }
        /*************************************************************
         * 登録ボタン押下時の処理
         *************************************************************/
        private void btnAppend_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("登録しますか?") == DialogResult.Yes)
            {
                // 登録データのオブジェクトを作成
                var entity = new Fare()
                {
                    code = textRegCode.Text,
                    year = Const.TARGET_YEAR,
                    name = textRegName.Text,
                    price_budget = Conversion.Parse(textRegPriceBudget.Text),
                    price_actual = Conversion.Parse(textRegPriceActual.Text),
                    note = textRegNote.Text,
                    update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                    update_date = DateTime.Now,
                    del_flg = Const.FLG_OFF
                };

                // データ登録処理(既に同じコードが存在する場合は登録しない)
                using (var context = new CostAccountingEntities())
                {
                    var target = from t in context.Fare
                                 where t.code.Equals(entity.code) && t.year.Equals(entity.year)
                                 select t;
                    if (target.Count() == 0)
                    {
                        context.Fare.Add(entity);
                        context.SaveChanges();

                        Logger.Info(Message.INF003, new string[] { this.Text, Message.create(textRegCode, textRegName) });
                        Program.MessageBoxAfter("登録しました。");

                        Form_Prepare_FareReg_Load(sender, e);
                    }
                    else
                    {
                        Program.MessageBoxError("既に同じコードの設備が登録されています。");
                    }

                }
            }
        }
        /*************************************************************
         * 登録ボタン押下時の処理
         *************************************************************/
        private void btnAppend_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("登録しますか?") == DialogResult.Yes)
            {
                // 登録データのオブジェクトを作成
                var entity = new ProductCode()
                {
                    code = textRegCode.Text,
                    year = Const.TARGET_YEAR,
                    name = textRegName.Text,
                    unit = textRegUnit.Text,
                    kbn = getProductKbn(groupKbn1),
                    note = textRegNote.Text,
                    update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                    update_date = DateTime.Now,
                    del_flg = Const.FLG_OFF
                };

                // データ登録処理(既に同じコードが存在する場合は登録しない)
                using (var context = new CostAccountingEntities())
                {
                    var target = from t in context.ProductCode
                                 where t.code.Equals(entity.code) && t.year.Equals(entity.year)
                                 select t;
                    if (target.Count() == 0)
                    {
                        context.ProductCode.Add(entity);
                        context.SaveChanges();

                        Logger.Info(Message.INF003, new string[] { this.Text, Message.create(textRegCode, textRegName) });
                        Program.MessageBoxAfter("登録し、再検索を行いました。");
                        btnSearch_Click(sender, e);
                    }
                    else
                    {
                        Program.MessageBoxError("既に同じコードの商品が登録されています。");
                    }

                }
            }
        }
 /*************************************************************
  * 検索ボタン押下時の処理
  *************************************************************/
 private void btnSearch_Click(object sender, EventArgs e)
 {
     using (var context = new CostAccountingEntities())
     {
         switch (type)
         {
             case Const.SEARCH_TYPE.Product:
                 searchProduct();
                 break;
             case Const.SEARCH_TYPE.Supplier:
                 searchSupplier();
                 break;
             case Const.SEARCH_TYPE.Material:
                 searchMaterial();
                 break;
             case Const.SEARCH_TYPE.Packing:
                 searchPacking();
                 break;
         }
     }
 }
Пример #6
0
        /*************************************************************
         * 指定した取引先の荷造運賃を返却する(ブレンド品用)
         *************************************************************/
        protected decimal getPackingFareForBlend(CostAccountingEntities context, Const.CATEGORY_TYPE category
                                                , string productCode, string supplierCode, decimal volume)
        {
            var blend = from t_blend in context.ProductBlend
                        join t_product in context.Product
                          on new { t_blend.year, t_blend.code, t_blend.category } equals new { t_product.year, t_product.code, t_product.category }
                        where t_blend.year.Equals(Const.TARGET_YEAR)
                              && t_blend.product_code.Equals(productCode)
                              && t_blend.category.Equals((int)category)
                        orderby t_blend.no
                        select new { t_blend, t_product };

            decimal packingFareSum = decimal.Zero;
            foreach (var data in blend)
            {
                decimal packingFare = getPackingFare(context, category, data.t_blend.code, supplierCode, data.t_product.volume);
                packingFareSum += decimal.Multiply(packingFare, data.t_blend.blend_rate);
            }
            return packingFareSum;
        }
        /*************************************************************
         * 登録処理を行う
         *************************************************************/
        private void executeAppend(CostAccountingEntities context)
        {
            int category = (int)Program.judgeCategory(radioBudget, radioActual);

            // 商品データの登録
            var entityProduct = new Product()
            {
                year = Const.TARGET_YEAR,
                code = productCode.Text,
                category = category,
                type = (int)Const.PRODUCT_TYPE.Normal,
                item_code = itemCode.SelectedValue.ToString(),
                volume = Conversion.Parse(volume.Text),
                packing = packing.Text,
                note = note.Text,
                material_cost = Conversion.Parse(materialCost.Text),
                labor_cost = Conversion.Parse(laborCost.Text),
                labor_cost_direct = Conversion.Parse(laborCostDirect.Text),
                labor_cost_indirect = Conversion.Parse(laborCostIndirect.Text),
                contractors_cost = Conversion.Parse(contractorsCost.Text),
                manufacturing_cost = Conversion.Parse(manufacturingCost.Text),
                materials_fare = Conversion.Parse(materialsFare.Text),
                packing_cost = Conversion.Parse(packingCost.Text),
                machine_cost = Conversion.Parse(machineCost.Text),
                utilities_cost = Conversion.Parse(utilitiesCost.Text),
                other_cost = Conversion.Parse(otherCost.Text),
                product_cost = Conversion.Parse(productCost.Text),
                packing_fare = Conversion.Parse(packingFare.Text),
                selling_cost = Conversion.Parse(sellingCost.Text),
                management_cost = Conversion.Parse(managementCost.Text),
                overall_cost = Conversion.Parse(overallCost.Text),
                preprocess_time_m = Conversion.Parse(preprocessTimeM.Text),
                preprocess_time_f = Conversion.Parse(preprocessTimeF.Text),
                night_time_m = Conversion.Parse(nightTimeM_indirect.Text),
                night_time_f = Conversion.Parse(nightTimeF.Text),
                dry_time_m = Conversion.Parse(dryTimeM.Text),
                dry_time_f = Conversion.Parse(dryTimeF.Text),
                selection_time_m = Conversion.Parse(selectionTimeM.Text),
                selection_time_f = Conversion.Parse(selectionTimeF.Text),
                tray_num = Conversion.Parse(trayNum.Text),
                update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                update_date = DateTime.Now,
                del_flg = Const.FLG_OFF
            };
            context.Product.Add(entityProduct);

            // 原料費データの登録
            int no = 0;
            foreach (DataGridViewRow row in dgvMaterialCost.Rows)
            {
                string code = (string)row.Cells["dgvMaterialCostName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductMaterial()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        quantity = Conversion.Parse((string)row.Cells["dgvMaterialCostQuantity"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductMaterial.Add(entity);
                }
            }

            // 外注費データの登録
            no = 0;
            foreach (DataGridViewRow row in dgvContractors.Rows)
            {
                string name = (string)row.Cells["dgvContractorsName"].Value;
                if (!String.IsNullOrEmpty(name))
                {
                    var entity = new ProductContractor()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        category = category,
                        no = no++,
                        name = name,
                        quantity = Conversion.Parse((string)row.Cells["dgvContractorsQuantity"].Value),
                        cost = Conversion.Parse((string)row.Cells["dgvContractorsCost"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductContractor.Add(entity);
                }
            }

            // 原料運賃データの登録
            no = 0;
            foreach (DataGridViewRow row in dgvMaterialsFare.Rows)
            {
                string name = (string)row.Cells["dgvMaterialsFareName"].Value;
                if (!String.IsNullOrEmpty(name))
                {
                    var entity = new ProductMaterialsFare()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        category = category,
                        no = no++,
                        name = name,
                        quantity = Conversion.Parse((string)row.Cells["dgvMaterialsFareQuantity"].Value),
                        cost = Conversion.Parse((string)row.Cells["dgvMaterialsFareCost"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductMaterialsFare.Add(entity);
                }
            }

            // 包装資材費データの登録
            no = 0;
            foreach (DataGridViewRow row in dgvPacking.Rows)
            {
                string code = (string)row.Cells["dgvPackingName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductPacking()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        quantity = Conversion.Parse((string)row.Cells["dgvPackingQuantity"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductPacking.Add(entity);
                }
            }

            // 設備費データの登録
            no = 0;
            foreach (DataGridViewRow row in dgvMachine.Rows)
            {
                string code = (string)row.Cells["dgvMachineName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductMachine()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        time = Conversion.Parse((string)row.Cells["dgvMachineTime"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductMachine.Add(entity);
                }
            }

            /** 2016.4.30 荷造運賃は取引先単位に登録できるように修正を行う。 start----
            // 荷造運賃
            no = 0;
            foreach (DataGridViewRow row in dgvPackingFare.Rows)
            {
                string code = (string)row.Cells["dgvPackingFareName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductPackingFare()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        supplier_code = suppllierCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        quantity = Conversion.Parse((string)row.Cells["dgvPackingFareQuantity"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductPackingFare.Add(entity);
                }
            }
            ----end */
        }
        /*************************************************************
         * 削除処理を行う
         *************************************************************/
        private void executeDelete(CostAccountingEntities context, bool delProduct)
        {
            int category = (int)Program.judgeCategory(radioBudget, radioActual);

            if (!delProduct)
            {
                // 同じ商品に紐づく取引先があるかチェックし、存在する場合は商品データを削除しない
                var supplierOther = from t in context.ProductSupplier
                                    where t.year.Equals(Const.TARGET_YEAR)
                                       && t.product_code.Equals(productCode.Text)
                                       && t.category.Equals(category)
                                       && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                                    select t;

                if (supplierOther.Count() > decimal.One)
                {
                    return;
                }
            }

            // 商品データ
            var product = from t in context.Product
                          where t.code.Equals(productCode.Text)
                             && t.year.Equals(Const.TARGET_YEAR)
                             && t.category.Equals(category)
                             && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                          select t;
            context.Product.RemoveRange(product);

            // 原料費データ
            var material = from t in context.ProductMaterial
                           where t.year.Equals(Const.TARGET_YEAR)
                              && t.product_code.Equals(productCode.Text)
                              && t.category.Equals(category)
                           select t;
            context.ProductMaterial.RemoveRange(material);

            // 外注費データ
            var contractor = from t in context.ProductContractor
                             where t.year.Equals(Const.TARGET_YEAR)
                                && t.product_code.Equals(productCode.Text)
                                && t.category.Equals(category)
                             select t;
            context.ProductContractor.RemoveRange(contractor);

            // 製造経費-原料運賃データ
            var materialFare = from t in context.ProductMaterialsFare
                               where t.year.Equals(Const.TARGET_YEAR)
                                  && t.product_code.Equals(productCode.Text)
                                  && t.category.Equals(category)
                               select t;
            context.ProductMaterialsFare.RemoveRange(materialFare);

            // 製造経費-包装資材費データ
            var packing = from t in context.ProductPacking
                          where t.year.Equals(Const.TARGET_YEAR)
                             && t.product_code.Equals(productCode.Text)
                             && t.category.Equals(category)
                          select t;
            context.ProductPacking.RemoveRange(packing);

            // 製造経費-設備費データ
            var machine = from t in context.ProductMachine
                          where t.year.Equals(Const.TARGET_YEAR)
                             && t.product_code.Equals(productCode.Text)
                             && t.category.Equals(category)
                          select t;
            context.ProductMachine.RemoveRange(machine);

            /** 2016.4.30 荷造運賃は取引先単位に登録できるように修正を行う。 start----
            // 製造経費-荷造運賃データ
            var packingFare = from t in context.ProductPackingFare
                              where t.year.Equals(Const.TARGET_YEAR)
                                 && t.product_code.Equals(productCode.Text)
                                 && t.supplier_code.Equals(suppllierCode.Text)
                                 && t.category.Equals(category)
                              select t;
            context.ProductPackingFare.RemoveRange(packingFare);
            ----end */
        }
Пример #9
0
        /*************************************************************
         * 指定した取引先の荷造運賃を返却する
         *************************************************************/
        protected decimal getPackingFare(CostAccountingEntities context, Const.CATEGORY_TYPE category
                                        , string productCode, string supplierCode, decimal volume)
        {
            var packingFare = from t in context.ProductPackingFare
                              where t.year.Equals(Const.TARGET_YEAR)
                                 && t.product_code.Equals(productCode)
                                 && t.supplier_code.Equals(supplierCode)
                                 && t.category.Equals((int)category)
                              select t;

            decimal sumCostKgPerAmount = 0;
            DataTable fare = DataTableSupport.getInstance(category).fare;
            foreach (var data in packingFare)
            {
                decimal amount = decimal.Multiply(data.quantity, DataTableSupport.getPrice(fare, data.code));
                decimal kgPerAmount = (volume != decimal.Zero ? decimal.Divide(amount, volume) : decimal.Zero);
                sumCostKgPerAmount += kgPerAmount;
            }
            return sumCostKgPerAmount;
        }
        /*************************************************************
         * 削除ボタン押下時の処理
         *************************************************************/
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("削除しますか?") == DialogResult.Yes)
            {
                using (var context = new CostAccountingEntities())
                {
                    var target = from t in context.ProductCode
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.code.Equals(textRegCode.Text)
                                 select t;

                    if (target.Count() > 0)
                    {
                        //target.First().del_flg = Const.FLG_ON;
                        context.ProductCode.Remove(target.First());
                    }
                    context.SaveChanges();
                }

                Logger.Info(Message.INF005, new string[] { this.Text, Message.create(textRegCode, textRegName) });
                Program.MessageBoxAfter("削除し、再検索を行いました。");
                btnSearch_Click(sender, e);
            }
        }
        /*************************************************************
         * 検索ボタン押下時の処理
         *************************************************************/
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string code = textSearchCode.Text;
            string name = textSearchName.Text;

            using (var context = new CostAccountingEntities())
            {
                var list = from t in context.ProductCode
                           where t.year.Equals(Const.TARGET_YEAR)
                              && (string.IsNullOrEmpty(code) || t.code.StartsWith(code))
                              && t.del_flg.Equals(Const.FLG_OFF)
                           orderby t.code
                           select new { t.code, t.name, t.unit, t.kbn, t.note };

                var ret = list.ToList();
                if (!string.IsNullOrEmpty(name))
                {
                    foreach (var data in list.ToList())
                        if (!data.name.Contains(name))
                            ret.Remove(data);
                }
                dataGridView.DataSource = ret;
            }

            SelectedRows();
        }
        /*************************************************************
         * 削除ボタン押下時の処理
         *************************************************************/
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string radioText = radioBudget.Checked ? "【予定】" : "【実績】";

            if (Program.MessageBoxBefore(radioText + "情報を削除しますか?") != DialogResult.Yes)
            {
                return;
            }

            // 削除処理を行う
            using (var context = new CostAccountingEntities())
            {
                executeDelete(context, false);
                executeDeleteSupplier(context);
                context.SaveChanges();
            }

            setProductData();
            setSupplierData();
            setOperationKbn();

            Logger.Info(Message.INF005, new string[] { this.Text, Message.create(productCode, suppllierCode) + radioText });
            Program.MessageBoxAfter("削除しました。");
        }
        /*************************************************************
         * フォームロード時の処理
         *************************************************************/
        private void Form_Prepare_OtherReg_Load(object sender, EventArgs e)
        {
            foreach (var control in tableLayoutPanel.Controls)
            {
                if (control is TextBox)
                    ((TextBox)control).Text = decimal.Zero.ToString("N");
            }

            // データの設定
            using (var context = new CostAccountingEntities())
            {
                // 予定データの設定
                var plan = from t in context.Other
                           where t.year.Equals(Const.TARGET_YEAR)
                              && t.category.Equals((int)Const.CATEGORY_TYPE.Budget)
                           select t;

                if (plan.Count() == decimal.One)
                {
                    wageM_plan.Text = plan.First().wage_m.ToString("N");
                    wageF_plan.Text = plan.First().wage_f.ToString("N");
                    wageIndirect_plan.Text = plan.First().wage_indirect.ToString("N");
                    utilitiesFD_plan.Text = plan.First().utilities_fd.ToString("N");
                    utilitiesAD_plan.Text = plan.First().utilities_ad.ToString("N");
                    allocationFD_plan.Text = plan.First().allocation_fd.ToString("N");
                    allocationAD_plan.Text = plan.First().allocation_ad.ToString("N");
                    allocationLabor_plan.Text = plan.First().allocation_labor.ToString("N");
                    allocationSale_plan.Text = plan.First().allocation_sale.ToString("N");
                    allocationMng_plan.Text = plan.First().allocation_mng.ToString("N");
                    allocationExt_plan.Text = plan.First().allocation_ext.ToString("N");
                    rateExpend_plan.Text = plan.First().rate_expend.ToString("N");
                    rateLoss_plan.Text = plan.First().rate_loss.ToString("N");
                    trayNum_plan.Text = plan.First().tray_num.ToString("N");
                }

                // 実績データの設定
                var actual = from t in context.Other
                             where t.year.Equals(Const.TARGET_YEAR)
                                && t.category.Equals((int)Const.CATEGORY_TYPE.Actual)
                             select t;

                if (actual.Count() == decimal.One)
                {
                    wageM_actual.Text = actual.First().wage_m.ToString("N");
                    wageF_actual.Text = actual.First().wage_f.ToString("N");
                    wageIndirect_actual.Text = actual.First().wage_indirect.ToString("N");
                    utilitiesFD_actual.Text = actual.First().utilities_fd.ToString("N");
                    utilitiesAD_actual.Text = actual.First().utilities_ad.ToString("N");
                    allocationFD_actual.Text = actual.First().allocation_fd.ToString("N");
                    allocationAD_actual.Text = actual.First().allocation_ad.ToString("N");
                    allocationLabor_actual.Text = actual.First().allocation_labor.ToString("N");
                    allocationSale_actual.Text = actual.First().allocation_sale.ToString("N");
                    allocationMng_actual.Text = actual.First().allocation_mng.ToString("N");
                    allocationExt_actual.Text = actual.First().allocation_ext.ToString("N");
                    rateExpend_actual.Text = actual.First().rate_expend.ToString("N");
                    rateLoss_actual.Text = actual.First().rate_loss.ToString("N");
                    trayNum_actual.Text = actual.First().tray_num.ToString("N");
                }
            }
        }
        /*************************************************************
         * 修正ボタン押下時の処理
         *************************************************************/
        private void btnChange_Click(object sender, EventArgs e)
        {
            string radioText = radioBudget.Checked ? "【予定】" : "【実績】";

            if (Program.MessageBoxBefore(radioText + "情報を修正しますか?") != DialogResult.Yes)
            {
                return;
            }

            // 念のため各種計算を行う
            calcAll();

            // 入力チェックを行う
            if (!checkInputData())
            {
                return;
            }

            // 削除→登録を行うことで、修正とする
            using (var context = new CostAccountingEntities())
            {
                executeDelete(context, true);
                executeAppend(context);
                executeChangeSupplier(context);
                context.SaveChanges();
            }

            setSupplierData();
            setOperationKbn();

            // 念のため各種計算を行う
            calcAll();

            Logger.Info(Message.INF004, new string[] { this.Text, Message.create(productCode, suppllierCode) + radioText });
            Program.MessageBoxAfter("修正しました。");
        }
        /*************************************************************
         * 検索した取引先データを設定する
         *************************************************************/
        private void setSupplierData()
        {
            using (var context = new CostAccountingEntities())
            {
                int category = (int)Program.judgeCategory(radioBudget, radioActual);
                var supplier = from t in context.ProductSupplier
                               where t.year.Equals(Const.TARGET_YEAR)
                                  && t.product_code.Equals(productCode.Text)
                                  && t.supplier_code.Equals(suppllierCode.Text)
                                  && t.category.Equals(category)
                                  && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                               select t;

                if (supplier.Count() == decimal.One)
                {
                    unitPrice.Text = supplier.First().unit_price.ToString("N");
                    updateTime.Text = supplier.First().update_date.ToString();
                    updatePC.Text = supplier.First().update_user;
                }
                else
                {
                    unitPrice.Text = String.Empty;
                    updateTime.Text = String.Empty;
                    updatePC.Text = String.Empty;
                }

                // 製造経費-荷造運賃データ
                dgvPackingFare.Rows.Clear();
                List<ProductPackingFare> packingFare = (from t in context.ProductPackingFare
                                                        where t.year.Equals(Const.TARGET_YEAR)
                                                           && t.product_code.Equals(productCode.Text)
                                                           && t.supplier_code.Equals(suppllierCode.Text)
                                                           && t.category.Equals(category)
                                                        orderby t.no
                                                        select t).ToList();
                dgvPackingFare.RowCount = packingFare.Count() + 1;
                for (int i = 0; i < packingFare.Count(); i++)
                {
                    dgvPackingFare.Rows[i].Cells["dgvPackingFareName"].Value = packingFare[i].code;
                    dgvPackingFare.Rows[i].Cells["dgvPackingFareQuantity"].Value = packingFare[i].quantity.ToString();
                    dgvPackingFare.Rows[i].Cells["dgvPackingFareCost"].Value = DataTableSupport.getPrice((DataTable)dgvPackingFareName.DataSource, packingFare[i].code).ToString("N");
                }
            }
        }
        /*************************************************************
         * 検索した商品データを設定する
         *************************************************************/
        private void setProductData()
        {
            using (var context = new CostAccountingEntities())
            {
                int category = (int)Program.judgeCategory(radioBudget, radioActual);
                var product = from t in context.Product
                              where t.code.Equals(productCode.Text)
                                 && t.year.Equals(Const.TARGET_YEAR)
                                 && t.category.Equals(category)
                                 && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                              select t;

                if (product.Count() == decimal.One)
                {
                    // 商品データの設定
                    itemCode.SelectedValue = product.First().item_code;
                    volume.Text = product.First().volume.ToString();
                    packing.Text = product.First().packing;
                    note.Text = product.First().note;
                    preprocessTimeM.Text = product.First().preprocess_time_m.ToString();
                    preprocessTimeF.Text = product.First().preprocess_time_f.ToString();
                    nightTimeM_indirect.Text = product.First().night_time_m.ToString();
                    nightTimeF.Text = product.First().night_time_f.ToString();
                    dryTimeM.Text = product.First().dry_time_m.ToString();
                    dryTimeF.Text = product.First().dry_time_f.ToString();
                    selectionTimeM.Text = product.First().selection_time_m.ToString();
                    selectionTimeF.Text = product.First().selection_time_f.ToString();
                    trayNum.Text = product.First().tray_num.ToString();

                    // 取引先データの設定
                    setSupplierData();

                    // 原料費データ
                    List<ProductMaterial> material = (from t in context.ProductMaterial
                                                      where t.year.Equals(Const.TARGET_YEAR)
                                                         && t.product_code.Equals(productCode.Text)
                                                         && t.category.Equals(category)
                                                      orderby t.no
                                                      select t).ToList();
                    dgvMaterialCost.RowCount = material.Count() + 1;
                    for (int i = 0; i < material.Count(); i++)
                    {
                        dgvMaterialCost.Rows[i].Cells["dgvMaterialCostName"].Value = material[i].code;
                        dgvMaterialCost.Rows[i].Cells["dgvMaterialCostQuantity"].Value = material[i].quantity.ToString();
                        dgvMaterialCost.Rows[i].Cells["dgvMaterialCostPrice"].Value = DataTableSupport.getPrice((DataTable)dgvMaterialCostName.DataSource, material[i].code).ToString("N");
                    }

                    // 外注費データ
                    List<ProductContractor> contractor = (from t in context.ProductContractor
                                                          where t.year.Equals(Const.TARGET_YEAR)
                                                             && t.product_code.Equals(productCode.Text)
                                                             && t.category.Equals(category)
                                                          orderby t.no
                                                          select t).ToList();
                    dgvContractors.RowCount = contractor.Count() + 1;
                    for (int i = 0; i < contractor.Count(); i++)
                    {
                        dgvContractors.Rows[i].Cells["dgvContractorsName"].Value = contractor[i].name;
                        dgvContractors.Rows[i].Cells["dgvContractorsQuantity"].Value = contractor[i].quantity.ToString();
                        dgvContractors.Rows[i].Cells["dgvContractorsCost"].Value = contractor[i].cost.ToString();
                    }

                    // 製造経費-原料運賃データ
                    List<ProductMaterialsFare> materialFare = (from t in context.ProductMaterialsFare
                                                               where t.year.Equals(Const.TARGET_YEAR)
                                                                  && t.product_code.Equals(productCode.Text)
                                                                  && t.category.Equals(category)
                                                               orderby t.no
                                                               select t).ToList();
                    dgvMaterialsFare.RowCount = materialFare.Count() + 1;
                    for (int i = 0; i < materialFare.Count(); i++)
                    {
                        dgvMaterialsFare.Rows[i].Cells["dgvMaterialsFareName"].Value = materialFare[i].name;
                        dgvMaterialsFare.Rows[i].Cells["dgvMaterialsFareQuantity"].Value = materialFare[i].quantity.ToString();
                        dgvMaterialsFare.Rows[i].Cells["dgvMaterialsFareCost"].Value = materialFare[i].cost.ToString();
                    }

                    // 製造経費-包装資材費データ
                    List<ProductPacking> packingList = (from t in context.ProductPacking
                                                        where t.year.Equals(Const.TARGET_YEAR)
                                                           && t.product_code.Equals(productCode.Text)
                                                           && t.category.Equals(category)
                                                        orderby t.no
                                                        select t).ToList();
                    dgvPacking.RowCount = packingList.Count() + 1;
                    for (int i = 0; i < packingList.Count(); i++)
                    {
                        dgvPacking.Rows[i].Cells["dgvPackingName"].Value = packingList[i].code;
                        dgvPacking.Rows[i].Cells["dgvPackingQuantity"].Value = packingList[i].quantity.ToString();
                        dgvPacking.Rows[i].Cells["dgvPackingCost"].Value = DataTableSupport.getPrice((DataTable)dgvPackingName.DataSource, packingList[i].code).ToString("N");
                    }

                    // 製造経費-設備費データ
                    List<ProductMachine> machine = (from t in context.ProductMachine
                                                    where t.year.Equals(Const.TARGET_YEAR)
                                                       && t.product_code.Equals(productCode.Text)
                                                       && t.category.Equals(category)
                                                    orderby t.no
                                                    select t).ToList();
                    dgvMachine.RowCount = machine.Count() + 1;
                    for (int i = 0; i < machine.Count(); i++)
                    {
                        dgvMachine.Rows[i].Cells["dgvMachineName"].Value = machine[i].code;
                        dgvMachine.Rows[i].Cells["dgvMachineTime"].Value = machine[i].time.ToString();
                        dgvMachine.Rows[i].Cells["dgvMachineRate"].Value = DataTableSupport.getPrice((DataTable)dgvMachineName.DataSource, machine[i].code).ToString("N");
                    }

                    /** 2016.4.30 荷造運賃は取引先単位に登録できるように修正を行う。 start----
                    // 製造経費-荷造運賃データ
                    List<ProductPackingFare> packingFare = (from t in context.ProductPackingFare
                                                            where t.year.Equals(Const.TARGET_YEAR)
                                                               && t.product_code.Equals(productCode.Text)
                                                               && t.category.Equals(category)
                                                            orderby t.no
                                                            select t).ToList();
                    dgvPackingFare.RowCount = packingFare.Count() + 1;
                    for (int i = 0; i < packingFare.Count(); i++)
                    {
                        dgvPackingFare.Rows[i].Cells["dgvPackingFareName"].Value = packingFare[i].code;
                        dgvPackingFare.Rows[i].Cells["dgvPackingFareQuantity"].Value = packingFare[i].quantity.ToString();
                        dgvPackingFare.Rows[i].Cells["dgvPackingFareCost"].Value = DataTableSupport.getPrice((DataTable)dgvPackingFareName.DataSource, packingFare[i].code).ToString("N");
                    }
                    ----end */

                }
                else
                {
                    // データクリア
                    itemCode.SelectedIndex = 0;
                    volume.Text = string.Empty;
                    trayNum.Text = string.Empty;
                    unitPrice.Text = string.Empty;
                    updateTime.Text = string.Empty;
                    updatePC.Text = string.Empty;
                    note.Text = string.Empty;
                    preprocessTimeM.Text = string.Empty;
                    preprocessTimeF.Text = string.Empty;
                    nightTimeM_indirect.Text = string.Empty;
                    nightTimeF.Text = string.Empty;
                    dryTimeM.Text = string.Empty;
                    dryTimeF.Text = string.Empty;
                    selectionTimeM.Text = string.Empty;
                    selectionTimeF.Text = string.Empty;
                    dgvMaterialCost.Rows.Clear();
                    dgvContractors.Rows.Clear();
                    dgvMaterialsFare.Rows.Clear();
                    dgvPacking.Rows.Clear();
                    dgvMachine.Rows.Clear();
                    initDgvMachineRow();
                    dgvPackingFare.Rows.Clear();
                }
            }
        }
        /*************************************************************
         * 処理区分の設定を行う
         *************************************************************/
        private void setOperationKbn()
        {
            if (!string.IsNullOrEmpty(productCode.Text) && !string.IsNullOrEmpty(suppllierCode.Text))
            {
                using (var context = new CostAccountingEntities())
                {
                    int category = (int)Program.judgeCategory(radioBudget, radioActual);

                    var target = from t_product in context.Product
                                 join t_supplier in context.ProductSupplier on
                                      new { t_product.year, t_product.code, t_product.category, t_product.type }
                                        equals
                                      new { t_supplier.year, code = t_supplier.product_code, t_supplier.category, t_supplier.type }
                                 where t_product.year.Equals(Const.TARGET_YEAR)
                                    && t_product.code.Equals(productCode.Text)
                                    && t_supplier.supplier_code.Equals(suppllierCode.Text)
                                    && t_product.category.Equals(category)
                                    && t_product.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                                 select t_product;

                    if (target.Count() > decimal.Zero)
                    {
                        operationKbn.Text = "修正";
                        btnAppend.Enabled = false;
                        btnChange.Enabled = true;
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        operationKbn.Text = "登録";
                        btnAppend.Enabled = true;
                        btnChange.Enabled = false;
                        btnDelete.Enabled = false;
                    }
                }
            }
            else
            {
                operationKbn.Text = "商品と取引先を選択";
                btnAppend.Enabled = false;
                btnChange.Enabled = false;
                btnDelete.Enabled = false;
            }
        }
        /*************************************************************
         * 取引先の削除処理を行う
         *************************************************************/
        private void executeDeleteSupplier(CostAccountingEntities context)
        {
            int category = (int)Program.judgeCategory(radioBudget, radioActual);

            var target = from t in context.ProductSupplier
                         where t.year.Equals(Const.TARGET_YEAR)
                            && t.product_code.Equals(productCode.Text)
                            && t.supplier_code.Equals(suppllierCode.Text)
                            && t.category.Equals(category)
                            && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                         select t;

            context.ProductSupplier.RemoveRange(target);

            // 製造経費-荷造運賃データ
            var packingFare = from t in context.ProductPackingFare
                              where t.year.Equals(Const.TARGET_YEAR)
                                 && t.product_code.Equals(productCode.Text)
                                 && t.supplier_code.Equals(suppllierCode.Text)
                                 && t.category.Equals(category)
                              select t;
            context.ProductPackingFare.RemoveRange(packingFare);
        }
        /*************************************************************
         * 初期データ登録ボタン押下時の処理
         *************************************************************/
        private void btnDefaultDataReg_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("初期データを登録しますか?" + Environment.NewLine + "※現在登録されているデータは削除されます※") == DialogResult.Yes)
            {
                using (var context = new CostAccountingEntities())
                {
                    // データ削除処理
                    var target = from t in context.Item
                                 where t.year.Equals(Const.TARGET_YEAR)
                                 select t;

                    context.Item.RemoveRange(target);

                    string itemData = Properties.Resources.defaultItemData;
                    string[] items = itemData.Split(',');

                    // データ登録処理
                    foreach (string item in items)
                    {
                        string[] data = item.Split('#');
                        var entity = new Item()
                        {
                            code = data[0],
                            year = Const.TARGET_YEAR,
                            name = data[1],
                            note = string.Empty,
                            update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                            update_date = DateTime.Now,
                            del_flg = Const.FLG_OFF
                        };
                        context.Item.Add(entity);
                    }
                    context.SaveChanges();
                }
                Program.MessageBoxAfter("登録しました。");
                Form_Prepare_ItemReg_Load(sender, e);
            }
        }
        /*************************************************************
         * 再計算ボタン押下時の処理
         *************************************************************/
        private void btnAllCalc_Click(object sender, EventArgs e)
        {
            string radioText = radioBudget.Checked ? "【予定】" : "【実績】";
            if (Program.MessageBoxBefore(radioText + "の全商品の再計算を行いますか?"
                                         + Environment.NewLine
                                         + "※商品の数におうじて時間がかかります。") != DialogResult.Yes)
            {
                return;
            }

            using (var context = new CostAccountingEntities())
            {
                int category = (int)Program.judgeCategory(radioBudget, radioActual);

                // 商品データの検索
                var target = from t in context.ProductSupplier
                             where t.year.Equals(Const.TARGET_YEAR)
                                && t.category.Equals((int)category)
                                && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                             orderby t.product_code, t.supplier_code
                             select t;
                var dataList = target.ToList();
                HashSet<string> already = new HashSet<string>();

                // プログレスバーの初期値を設定
                progressBar.Minimum = 0;
                progressBar.Maximum = dataList.Count;
                progressBar.Value = 0;
                progressBar.Step = 1;
                for (int i = 0; i < dataList.Count; i++)
                {
                    productCode.Text = dataList[i].product_code;
                    suppllierCode.Text = dataList[i].supplier_code;

                    // データを設定の上、再計算
                    setProductData();
                    setSupplierData();
                    calcAll();

                    // 再計算結果をDBに反映する。
                    if (!already.Contains(productCode.Text))
                    {
                        // 商品は未計算のデータのみ反映対象とする
                        executeDelete(context, true);
                        executeAppend(context);
                        already.Add(productCode.Text);
                    }
                    executeChangeSupplier(context);

                    // プログレスバーの値を更新
                    labelStatus.Refresh();
                    labelStatus.Text = string.Format("・・・ ( {0} / {1} )"
                                                     , (i + 1).ToString("#,0")
                                                     , progressBar.Maximum.ToString("#,0"));
                    progressBar.PerformStep();
                }

                context.SaveChanges();
                Logger.Info(Message.INF007, new string[] { this.Text, Message.create(labelStatus) + radioText });
                Program.MessageBoxAfter("再計算しました。");

                // データクリア
                productCode.Text = string.Empty;
                suppllierCode.Text = string.Empty;
                itemCode.SelectedIndex = 0;
                packing.Text = string.Empty;
                volume.Text = string.Empty;
                trayNum.Text = string.Empty;
                unitPrice.Text = string.Empty;
                updateTime.Text = string.Empty;
                updatePC.Text = string.Empty;
                note.Text = string.Empty;
                preprocessTimeM.Text = string.Empty;
                preprocessTimeF.Text = string.Empty;
                nightTimeM_indirect.Text = string.Empty;
                nightTimeF.Text = string.Empty;
                dryTimeM.Text = string.Empty;
                dryTimeF.Text = string.Empty;
                selectionTimeM.Text = string.Empty;
                selectionTimeF.Text = string.Empty;
                dgvMaterialCost.Rows.Clear();
                dgvContractors.Rows.Clear();
                dgvMaterialsFare.Rows.Clear();
                dgvPacking.Rows.Clear();
                dgvMachine.Rows.Clear();
                initDgvMachineRow();
                dgvPackingFare.Rows.Clear();
                calcAll();
            }
        }
        /*************************************************************
         * フォーム終了時の処理
         *************************************************************/
        private void Form_Common_SelectYear_FormClosing(object sender, FormClosingEventArgs e)
        {
            // DBファイルのバキューム処理
            string dbPath = System.Configuration.ConfigurationManager.AppSettings["dbPath"];
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))
            {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = "vacuum;";
                    command.ExecuteNonQuery();
                }
            }

            // DBサイズの記録
            string today = DateTime.Now.ToString("yyyyMMdd");

            using (var context = new CostAccountingEntities())
            {
                var target = from t in context.DbSize
                             where t.ymd.Equals(today)
                             select t;

                if (target.Count() == decimal.Zero)
                {

                    // 登録データのオブジェクトを作成
                    DateTime dt = DateTime.Now;
                    var entity = new DbSize()
                    {
                        ymd = today,
                        size = new FileInfo(dbPath).Length / 1024,  // KB単位でDBファイルのサイズを記録
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now
                    };

                    // データ登録
                    context.DbSize.Add(entity);
                }
                else
                {
                    target.First().size = new FileInfo(dbPath).Length / 1024;  // KB単位でDBファイルのサイズを記録
                    target.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                    target.First().update_date = DateTime.Now;
                }
                context.SaveChanges();
            }

            // DBファイルのバックアップ
            string bkDir = new FileInfo(dbPath).DirectoryName + @"\" + "backup";

            if (!Directory.Exists(bkDir))
                Directory.CreateDirectory(bkDir);

            FileInfo dbFile = new FileInfo(dbPath);
            string bkFile = bkDir + @"\" + dbFile.Name + "." + today;
            dbFile.CopyTo(bkFile, true);

            // 一定期間を過ぎたDBのバックアップファイルを削除する
            foreach (string file in Directory.GetFiles(bkDir))
            {
                FileInfo target = new FileInfo(file);
                string ymd = target.Extension.TrimStart('.');

                today = Regex.Replace(today, @"(\d{4})(\d{2})(\d{2})", @"$1/$2/$3");
                ymd = Regex.Replace(ymd, @"(\d{4})(\d{2})(\d{2})", @"$1/$2/$3");

                TimeSpan span = DateTime.Parse(today) - DateTime.Parse(ymd);

                if (span.Days > Conversion.Parse(Properties.Resources.bkfileStoragePeriod))
                    target.Delete();
            }

            Logger.Info(Message.INF002);
        }
Пример #22
0
        /*************************************************************
         * 固定費データを画面に設定
         *************************************************************/
        protected void setDataFixedCost()
        {
            for (int columnIdx = 40; columnIdx <= 49; columnIdx++)
                dataGridViewTotal.Rows[0].Cells[columnIdx].Value = decimal.Zero.ToString("#,0");

            using (var context = new CostAccountingEntities())
            {
                string inStr = string.Empty;
                foreach (CheckBox target in checkBoxMonthDic.Keys)
                {
                    if (target.Checked)
                        inStr += string.Concat(checkBoxMonthDic[target], ",");
                }

                inStr = inStr.TrimEnd(',');

                var targetData = from t in context.CostMngTotal
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.category.Equals((int)category)
                                    && inStr.Contains(t.month.ToString())
                                    && t.del_flg.Equals(Const.FLG_OFF)
                                 select t;

                foreach (var data in targetData.ToList())
                {
                    dataGridViewTotal.Rows[0].Cells[40].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[40].Value), data.manufacturing_personnel).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[41].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[41].Value), data.manufacturing_depreciation).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[42].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[42].Value), data.manufacturing_rent).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[43].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[43].Value), data.manufacturing_repair).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[44].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[44].Value), data.manufacturing_stock).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[45].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[45].Value), data.manufacturing_other).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[46].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[46].Value), data.selling_personnel).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[47].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[47].Value), data.selling_depreciation).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[48].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[48].Value), data.selling_other).ToString("#,0");
                    dataGridViewTotal.Rows[0].Cells[49].Value = decimal.Add(Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[49].Value), data.operating_expenses).ToString("#,0");
                }
            }
        }
        /*************************************************************
         * 登録ボタン押下時の処理
         *************************************************************/
        private void btnAppend_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("登録しますか?") != DialogResult.Yes)
                return;

            // データ登録処理(削除→登録を行う)
            using (var context = new CostAccountingEntities())
            {
                // データ削除
                var target = from t in context.Other
                             where t.year.Equals(Const.TARGET_YEAR)
                             select t;
                context.Other.RemoveRange(target);

                // データ登録
                var plan = new Other()
                {
                    year = Const.TARGET_YEAR,
                    category = (int)Const.CATEGORY_TYPE.Budget,
                    wage_m = Conversion.Parse(wageM_plan.Text),
                    wage_f = Conversion.Parse(wageF_plan.Text),
                    wage_indirect = Conversion.Parse(wageIndirect_plan.Text),
                    utilities_fd = Conversion.Parse(utilitiesFD_plan.Text),
                    utilities_ad = Conversion.Parse(utilitiesAD_plan.Text),
                    allocation_fd = Conversion.Parse(allocationFD_plan.Text),
                    allocation_ad = Conversion.Parse(allocationAD_plan.Text),
                    allocation_labor = Conversion.Parse(allocationLabor_plan.Text),
                    allocation_sale = Conversion.Parse(allocationSale_plan.Text),
                    allocation_mng = Conversion.Parse(allocationMng_plan.Text),
                    allocation_ext = Conversion.Parse(allocationExt_plan.Text),
                    rate_expend = Conversion.Parse(rateExpend_plan.Text),
                    rate_loss = Conversion.Parse(rateLoss_plan.Text),
                    tray_num = Conversion.Parse(trayNum_plan.Text),
                    update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                    update_date = DateTime.Now,
                    del_flg = Const.FLG_OFF
                };

                var actual = new Other()
                {
                    year = Const.TARGET_YEAR,
                    category = (int)Const.CATEGORY_TYPE.Actual,
                    wage_m = Conversion.Parse(wageM_actual.Text),
                    wage_f = Conversion.Parse(wageF_actual.Text),
                    wage_indirect = Conversion.Parse(wageIndirect_actual.Text),
                    utilities_fd = Conversion.Parse(utilitiesFD_actual.Text),
                    utilities_ad = Conversion.Parse(utilitiesAD_actual.Text),
                    allocation_fd = Conversion.Parse(allocationFD_actual.Text),
                    allocation_ad = Conversion.Parse(allocationAD_actual.Text),
                    allocation_labor = Conversion.Parse(allocationLabor_actual.Text),
                    allocation_sale = Conversion.Parse(allocationSale_actual.Text),
                    allocation_mng = Conversion.Parse(allocationMng_actual.Text),
                    allocation_ext = Conversion.Parse(allocationExt_actual.Text),
                    rate_expend = Conversion.Parse(rateExpend_actual.Text),
                    rate_loss = Conversion.Parse(rateLoss_actual.Text),
                    tray_num = Conversion.Parse(trayNum_actual.Text),
                    update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                    update_date = DateTime.Now,
                    del_flg = Const.FLG_OFF
                };

                context.Other.Add(plan);
                context.Other.Add(actual);
                context.SaveChanges();
            }

            Logger.Info(Message.INF003, new string[] { this.Text, "-" });
            Program.MessageBoxAfter("登録しました。");
        }
        /*************************************************************
         * フォームロード時の処理
         *************************************************************/
        private void Form_Prepare_ProductReg_Load(object sender, EventArgs e)
        {
            using (var context = new CostAccountingEntities())
            {
                var list = from t in context.ProductCode
                           where t.year.Equals(Const.TARGET_YEAR)
                              && t.del_flg.Equals(Const.FLG_OFF)
                           orderby t.code
                           select new { t.code, t.name, t.unit, t.kbn, t.note };

                dataGridView.DataSource = list.ToList();
            }

            SelectedRows();
        }
        /*************************************************************
         * CSVファイル登録ボタン押下時の処理
         *************************************************************/
        private void btnFileReg_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(labelFilePath.Text))
            {
                Program.MessageBoxError("CSVファイルを選択してください。");
                return;

            }

            string productKbn = getProductKbn(groupKbn2);
            if (string.IsNullOrEmpty(productKbn))
            {
                Program.MessageBoxError("商品区分を選択してください。");
                return;
            }

            if (Program.MessageBoxBefore(productKbn + "として登録しますか?" + Environment.NewLine
                + "※現在登録されている" + productKbn + "データは削除されます※") == DialogResult.Yes)
            {
                using (var context = new CostAccountingEntities())
                {
                    // データ削除処理
                    var target = from t in context.ProductCode
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.kbn.Equals(productKbn)
                                 select t;

                    context.ProductCode.RemoveRange(target);

                    // データ登録処理
                    foreach (ListViewItem items in listView.Items)
                    {
                        // 登録データのオブジェクトを作成
                        var entity = new ProductCode()
                        {
                            code = items.SubItems[0].Text,
                            year = Const.TARGET_YEAR,
                            name = items.SubItems[1].Text,
                            unit = items.SubItems[2].Text,
                            kbn = productKbn,
                            note = string.Empty,
                            update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                            update_date = DateTime.Now,
                            del_flg = Const.FLG_OFF
                        };
                        context.ProductCode.Add(entity);
                    }
                    context.SaveChanges();
                }

                Logger.Info(Message.INF003, new string[] { this.Text, Message.create(labelFilePath, recordCnt) + productKbn });
                Program.MessageBoxAfter("登録し、再検索を行いました。");
                btnSearch_Click(sender, e);
            }
        }
        /*************************************************************
         * 取引先の登録処理を行う
         *************************************************************/
        private void executeAppendSupplier(CostAccountingEntities context)
        {
            int category = (int)Program.judgeCategory(radioBudget, radioActual);

            // 取引先データの登録
            var entitySupplier = new ProductSupplier()
            {
                year = Const.TARGET_YEAR,
                product_code = productCode.Text,
                supplier_code = suppllierCode.Text,
                category = category,
                type = (int)Const.PRODUCT_TYPE.Normal,
                unit_price = Conversion.Parse(unitPrice.Text),
                update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                update_date = DateTime.Now,
                del_flg = Const.FLG_OFF
            };
            context.ProductSupplier.Add(entitySupplier);

            // 荷造運賃
            int no = 0;
            foreach (DataGridViewRow row in dgvPackingFare.Rows)
            {
                string code = (string)row.Cells["dgvPackingFareName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductPackingFare()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        supplier_code = suppllierCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        quantity = Conversion.Parse((string)row.Cells["dgvPackingFareQuantity"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductPackingFare.Add(entity);
                }
            }
        }
Пример #27
0
        /*************************************************************
         * 登録ボタン押下時の処理
         *************************************************************/
        protected void btnAppend_Click(object sender, EventArgs e)
        {
            if (Program.MessageBoxBefore("登録しますか?") != DialogResult.Yes)
            {
                return;
            }

            // 入力チェックを行う
            if (!checkInputData())
            {
                return;
            }

            // 登録処理を行う
            using (var context = new CostAccountingEntities())
            {
                //----------------------------------------- 商品と取引先ごとの各月の入力内容を登録
                foreach (DataGridViewRow row in dataGridView.Rows)
                {

                    string productCode = (string)row.Cells["product_code"].Value;
                    string supplierCode = (string)row.Cells["supplier_code"].Value;
                    int type = (int)row.Cells["type"].Value;

                    var target = from t in context.ProductSupplier
                                 where t.year.Equals(Const.TARGET_YEAR)
                                    && t.product_code.Equals(productCode)
                                    && t.supplier_code.Equals(supplierCode)
                                    && t.category.Equals((int)category)
                                    && t.type.Equals(type)
                                 select t;

                    if (target.Count() > 0)
                    {
                        target.First().month_04 = Conversion.Parse((string)row.Cells[16].Value);
                        target.First().month_05 = Conversion.Parse((string)row.Cells[17].Value);
                        target.First().month_06 = Conversion.Parse((string)row.Cells[18].Value);
                        target.First().month_07 = Conversion.Parse((string)row.Cells[19].Value);
                        target.First().month_08 = Conversion.Parse((string)row.Cells[20].Value);
                        target.First().month_09 = Conversion.Parse((string)row.Cells[21].Value);
                        target.First().month_10 = Conversion.Parse((string)row.Cells[22].Value);
                        target.First().month_11 = Conversion.Parse((string)row.Cells[23].Value);
                        target.First().month_12 = Conversion.Parse((string)row.Cells[24].Value);
                        target.First().month_01 = Conversion.Parse((string)row.Cells[25].Value);
                        target.First().month_02 = Conversion.Parse((string)row.Cells[26].Value);
                        target.First().month_03 = Conversion.Parse((string)row.Cells[27].Value);
                        target.First().num01 = Conversion.Parse((string)row.Cells["num01"].Value);
                        target.First().num02 = Conversion.Parse((string)row.Cells["num02"].Value);
                        target.First().num03 = Conversion.Parse((string)row.Cells["num03"].Value);
                        target.First().num04 = Conversion.Parse((string)row.Cells["num04"].Value);
                        target.First().num05 = Conversion.Parse((string)row.Cells["num05"].Value);
                        target.First().num06 = Conversion.Parse((string)row.Cells["num06"].Value);
                        target.First().num07 = Conversion.Parse((string)row.Cells["num07"].Value);
                        target.First().num08 = Conversion.Parse((string)row.Cells["num08"].Value);
                        target.First().num09 = Conversion.Parse((string)row.Cells["num09"].Value);
                        target.First().num10 = Conversion.Parse((string)row.Cells["num10"].Value);
                        target.First().num11 = Conversion.Parse((string)row.Cells["num11"].Value);
                        target.First().num12 = Conversion.Parse((string)row.Cells["num12"].Value);

                        // 商品登録時の登録ユーザと更新日時を維持するため、ここでは更新対象外とする
                        // target.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                        // target.First().update_date = DateTime.Now;
                    }
                }

                //----------------------------------------- 実績登録の場合は、乖離幅測定データも登録
                if (Const.CATEGORY_TYPE.Actual.Equals(category))
                {
                    Dictionary<CheckBox, bool> prevState = new Dictionary<CheckBox, bool>();

                    foreach (CheckBox target in checkBoxMonthDic.Keys)
                        prevState.Add(target, target.Checked);

                    foreach (CheckBox target in checkBoxMonthDic.Keys)
                    {
                        target.Checked = true;
                        foreach (CheckBox other in checkBoxMonthDic.Keys)
                        {
                            if (!target.Equals(other))
                                other.Checked = false;
                        }

                        int month = checkBoxMonthDic[target];
                        var divergence = from t in context.Divergence
                                         where t.year.Equals(Const.TARGET_YEAR)
                                            && t.month.Equals(month)
                                            && t.del_flg.Equals(Const.FLG_OFF)
                                         select t;

                        if (divergence.Count() == 0)
                        {
                            // 登録処理
                            var entity = new Divergence()
                            {
                                year = Const.TARGET_YEAR,
                                month = month,
                                materialCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[29].Value),
                                laborCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[30].Value),
                                contractorsCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[31].Value),
                                materialsFare_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[32].Value),
                                packingCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[33].Value),
                                utilitiesCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[34].Value),
                                otherCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[35].Value),
                                packingFare_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[36].Value),
                                update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                                update_date = DateTime.Now,
                                del_flg = Const.FLG_OFF
                            };
                            context.Divergence.Add(entity);
                        }
                        else
                        {
                            // 更新処理
                            divergence.First().materialCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[29].Value);
                            divergence.First().laborCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[30].Value);
                            divergence.First().contractorsCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[31].Value);
                            divergence.First().materialsFare_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[32].Value);
                            divergence.First().packingCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[33].Value);
                            divergence.First().utilitiesCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[34].Value);
                            divergence.First().otherCost_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[35].Value);
                            divergence.First().packingFare_costing = Conversion.Parse((string)dataGridViewTotal.Rows[0].Cells[36].Value);
                            divergence.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                            divergence.First().update_date = DateTime.Now;
                        }
                    }

                    foreach (CheckBox target in checkBoxMonthDic.Keys)
                        target.Checked = prevState[target];
                }

                context.SaveChanges();
            }

            Program.MessageBoxAfter("登録しました。");
        }
        /*************************************************************
         * 取引先の修正処理を行う
         *************************************************************/
        private void executeChangeSupplier(CostAccountingEntities context)
        {
            int category = (int)Program.judgeCategory(radioBudget, radioActual);

            var target = from t in context.ProductSupplier
                         where t.year.Equals(Const.TARGET_YEAR)
                            && t.product_code.Equals(productCode.Text)
                            && t.supplier_code.Equals(suppllierCode.Text)
                            && t.category.Equals(category)
                            && t.type.Equals((int)Const.PRODUCT_TYPE.Normal)
                         select t;

            if (target.Count() > decimal.Zero)
            {
                target.First().unit_price = Conversion.Parse(unitPrice.Text);
                target.First().update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName);
                target.First().update_date = DateTime.Now;
            }

            // 荷造運賃データは、削除→登録により修正とみなす。
            // 削除
            var packingFare = from t in context.ProductPackingFare
                              where t.year.Equals(Const.TARGET_YEAR)
                                 && t.product_code.Equals(productCode.Text)
                                 && t.supplier_code.Equals(suppllierCode.Text)
                                 && t.category.Equals(category)
                              select t;
            context.ProductPackingFare.RemoveRange(packingFare);

            // 登録
            int no = 0;
            foreach (DataGridViewRow row in dgvPackingFare.Rows)
            {
                string code = (string)row.Cells["dgvPackingFareName"].Value;
                if (!String.IsNullOrEmpty(code))
                {
                    var entity = new ProductPackingFare()
                    {
                        year = Const.TARGET_YEAR,
                        product_code = productCode.Text,
                        supplier_code = suppllierCode.Text,
                        category = category,
                        no = no++,
                        code = code,
                        quantity = Conversion.Parse((string)row.Cells["dgvPackingFareQuantity"].Value),
                        update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName),
                        update_date = DateTime.Now,
                        del_flg = Const.FLG_OFF
                    };
                    context.ProductPackingFare.Add(entity);
                }
            }
        }
Пример #29
0
        /*************************************************************
         * データを画面に設定
         *************************************************************/
        private void setData()
        {
            using (var context = new CostAccountingEntities())
            {
                //------------------------------------------------------------------------------ 各商品の入力値を設定
                var target = from t in
                                 (
                                   from product in context.Product
                                   join supplier in context.ProductSupplier
                                   on new { product.year, product.code, product.category, product.type }
                                      equals
                                      new { supplier.year, code = supplier.product_code, supplier.category, supplier.type }
                                   where product.year.Equals(Const.TARGET_YEAR)
                                      && product.category.Equals((int)category)
                                   select new { product, supplier }
                                 )
                             join m_product in context.ProductCode
                                  on new { t.product.year, code = t.product.code } equals new { m_product.year, m_product.code }
                             join m_supplier in context.Supplier
                                  on new { t.supplier.year, code = t.supplier.supplier_code } equals new { m_supplier.year, m_supplier.code }
                             join m_item in context.Item
                                  on new { t.product.year, code = t.product.item_code } equals new { m_item.year, m_item.code }
                             orderby t.supplier.supplier_code, t.product.code, t.supplier.type
                             select new { t_product = t.product, t_supplier = t.supplier, m_product, m_supplier, m_item };

                var dataList = target.ToList();
                dataGridView.RowCount = dataList.Count;

                decimal rateExpend = decimal.Divide(Parameters.getInstance(category).rateExpend, 100);
                for (int i = 0; i < dataList.Count; i++)
                {
                    dataGridView.Rows[i].Cells[0].Value = (i + 1).ToString();
                    dataGridView.Rows[i].Cells[1].Value = dataList[i].m_item.name;
                    dataGridView.Rows[i].Cells[2].Value = dataList[i].m_supplier.name;
                    dataGridView.Rows[i].Cells[3].Value = dataList[i].m_product.name;
                    dataGridView.Rows[i].Cells[4].Value = dataList[i].t_supplier.unit_price.ToString("#,0");
                    dataGridView.Rows[i].Cells[5].Value = dataList[i].t_product.material_cost.ToString("#,0");
                    dataGridView.Rows[i].Cells[6].Value = dataList[i].t_product.labor_cost_direct.ToString("#,0");
                    dataGridView.Rows[i].Cells[7].Value = dataList[i].t_product.contractors_cost.ToString("#,0");
                    dataGridView.Rows[i].Cells[8].Value = dataList[i].t_product.materials_fare.ToString("#,0");
                    dataGridView.Rows[i].Cells[9].Value = dataList[i].t_product.packing_cost.ToString("#,0");
                    dataGridView.Rows[i].Cells[10].Value = dataList[i].t_product.utilities_cost.ToString("#,0");
                    dataGridView.Rows[i].Cells[11].Value = decimal.Multiply(dataList[i].t_product.other_cost, rateExpend).ToString("#,0");

                    //----------------------------------------------------------------------------------------------
                    // 荷造運賃は、取引先単位に計算した金額を設定するよう修正(2016/10/09)
                    // ↓ここから
                    //----------------------------------------------------------------------------------------------
                    // dataGridView.Rows[i].Cells[12].Value = dataList[i].t_product.packing_fare.ToString("#,0");
                    int type = dataList[i].t_product.type;
                    if (type == (int)Const.PRODUCT_TYPE.Normal)
                    {
                        dataGridView.Rows[i].Cells[12].Value = getPackingFare(context, category, dataList[i].m_product.code, dataList[i].m_supplier.code, dataList[i].t_product.volume).ToString("#,0");
                    }
                    else if (type == (int)Const.PRODUCT_TYPE.Blend)
                    {
                        dataGridView.Rows[i].Cells[12].Value = getPackingFareForBlend(context, category, dataList[i].m_product.code, dataList[i].m_supplier.code, dataList[i].t_product.volume).ToString("#,0");
                    }
                    else
                    {
                        throw new Exception("商品タイプが不正:" + type);
                    }
                    //----------------------------------------------------------------------------------------------
                    // ↑ここまで
                    //----------------------------------------------------------------------------------------------

                    dataGridView.Rows[i].Cells[13].Value = (dataList[i].t_product.material_cost
                                                            + dataList[i].t_product.labor_cost_direct
                                                            + dataList[i].t_product.contractors_cost
                                                            + dataList[i].t_product.materials_fare
                                                            + dataList[i].t_product.packing_cost
                                                            + dataList[i].t_product.utilities_cost
                                                            + decimal.Multiply(dataList[i].t_product.other_cost, rateExpend)
                                                            + dataList[i].t_product.packing_fare).ToString("#,0");

                    dataGridView.Rows[i].Cells[14].Value = decimal.Subtract(Conversion.Parse((string)dataGridView.Rows[i].Cells[4].Value)
                                                                            , Conversion.Parse((string)dataGridView.Rows[i].Cells[13].Value)).ToString("#,0");

                    dataGridView.Rows[i].Cells[16].Value = dataList[i].t_supplier.month_04.ToString("#,0");
                    dataGridView.Rows[i].Cells[17].Value = dataList[i].t_supplier.month_05.ToString("#,0");
                    dataGridView.Rows[i].Cells[18].Value = dataList[i].t_supplier.month_06.ToString("#,0");
                    dataGridView.Rows[i].Cells[19].Value = dataList[i].t_supplier.month_07.ToString("#,0");
                    dataGridView.Rows[i].Cells[20].Value = dataList[i].t_supplier.month_08.ToString("#,0");
                    dataGridView.Rows[i].Cells[21].Value = dataList[i].t_supplier.month_09.ToString("#,0");
                    dataGridView.Rows[i].Cells[22].Value = dataList[i].t_supplier.month_10.ToString("#,0");
                    dataGridView.Rows[i].Cells[23].Value = dataList[i].t_supplier.month_11.ToString("#,0");
                    dataGridView.Rows[i].Cells[24].Value = dataList[i].t_supplier.month_12.ToString("#,0");
                    dataGridView.Rows[i].Cells[25].Value = dataList[i].t_supplier.month_01.ToString("#,0");
                    dataGridView.Rows[i].Cells[26].Value = dataList[i].t_supplier.month_02.ToString("#,0");
                    dataGridView.Rows[i].Cells[27].Value = dataList[i].t_supplier.month_03.ToString("#,0");
                    dataGridView.Rows[i].Cells["product_code"].Value = dataList[i].t_supplier.product_code;
                    dataGridView.Rows[i].Cells["supplier_code"].Value = dataList[i].t_supplier.supplier_code;
                    dataGridView.Rows[i].Cells["type"].Value = dataList[i].t_supplier.type;
                    dataGridView.Rows[i].Cells["num04"].Value = dataList[i].t_supplier.num04.ToString("N");
                    dataGridView.Rows[i].Cells["num05"].Value = dataList[i].t_supplier.num05.ToString("N");
                    dataGridView.Rows[i].Cells["num06"].Value = dataList[i].t_supplier.num06.ToString("N");
                    dataGridView.Rows[i].Cells["num07"].Value = dataList[i].t_supplier.num07.ToString("N");
                    dataGridView.Rows[i].Cells["num08"].Value = dataList[i].t_supplier.num08.ToString("N");
                    dataGridView.Rows[i].Cells["num09"].Value = dataList[i].t_supplier.num09.ToString("N");
                    dataGridView.Rows[i].Cells["num10"].Value = dataList[i].t_supplier.num10.ToString("N");
                    dataGridView.Rows[i].Cells["num11"].Value = dataList[i].t_supplier.num11.ToString("N");
                    dataGridView.Rows[i].Cells["num12"].Value = dataList[i].t_supplier.num12.ToString("N");
                    dataGridView.Rows[i].Cells["num01"].Value = dataList[i].t_supplier.num01.ToString("N");
                    dataGridView.Rows[i].Cells["num02"].Value = dataList[i].t_supplier.num02.ToString("N");
                    dataGridView.Rows[i].Cells["num03"].Value = dataList[i].t_supplier.num03.ToString("N");
                }

                //------------------------------------------------------------------------------ 固定費を設定
                setDataFixedCost();
            }
        }
        /*************************************************************
         * 登録ボタン押下時の処理
         *************************************************************/
        private void btnAppend_Click(object sender, EventArgs e)
        {
            string radioText = radioBudget.Checked ? "【予定】" : "【実績】";

            string msg = radioText + "情報を登録しますか?";
            msg = radioBudget.Checked ? string.Concat(msg, Environment.NewLine, "※実績情報にもコピーします。") : msg;

            if (Program.MessageBoxBefore(msg) != DialogResult.Yes)
            {
                return;
            }

            // 念のため各種計算を行う
            calcAll();

            // 入力チェックを行う
            if (!checkInputData())
            {
                return;
            }

            // 登録処理を行う
            using (var context = new CostAccountingEntities())
            {
                executeDelete(context, true);
                executeAppend(context);
                executeAppendSupplier(context);

                // 予定の場合は実績も同データで登録する
                if (radioBudget.Checked)
                {
                    radioActual.CheckedChanged -= new EventHandler(radio_CheckedChanged);
                    radioBudget.CheckedChanged -= new EventHandler(radio_CheckedChanged);

                    radioActual.Checked = true;
                    executeDelete(context, true);
                    executeAppend(context);
                    executeDeleteSupplier(context);
                    executeAppendSupplier(context);
                    radioBudget.Checked = true;

                    radioActual.CheckedChanged += new EventHandler(radio_CheckedChanged);
                    radioBudget.CheckedChanged += new EventHandler(radio_CheckedChanged);
                }
                context.SaveChanges();
            }

            setSupplierData();
            setOperationKbn();

            // 念のため各種計算を行う
            calcAll();

            Logger.Info(Message.INF003, new string[] { this.Text, Message.create(productCode, suppllierCode) + radioText });
            Program.MessageBoxAfter("登録しました。");
        }