// Use this for initialization
    void Start()
    {
        pointDeVieMax = 10;
        pointDeVie = pointDeVieMax - 5;

        inventaire = new List<Objet>();

        Ration res = new Ration();
        inventaire.Add(res);
    }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (dgv1.RowCount < 1)
            {
                return;
            }
            Site = cmb_site.SelectedValue.ToString();
            if (Site == string.Empty)
            {
                MessageBox.Show("请选择ERP域!");
                return;
            }
            #region 开始循环比对Excel中的每行的材料号是否都对。
            for (int i = 0; i < dgv1.RowCount - 1; i++)
            {
                string partno = dgv1.Rows[i].Cells[4].Value.ToString();
                if (string.IsNullOrEmpty(partno))
                {
                    //MessageBox.Show("第" + (i + 1) + "行此材料编码不存在");
                    //return;
                }
                else
                {
                    InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site);
                    if (invpartnew != null)
                    {
                    }
                    else
                    {
                        MessageBox.Show("第" + (i + 1) + "行ERP中无此材料编码");
                        return;
                    }
                }
            }
            #endregion

            string appdir = System.AppDomain.CurrentDomain.BaseDirectory;
            InitializeWorkbook(@appdir + "Template\\项目MSS明细表.xls");
            ISheet sheet1 = hssfworkbook.GetSheet("MSS明细表");

            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
            //sheet1.GetRow(1).GetCell(1).SetCellValue(200200);
            //sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            //sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            //sheet1.GetRow(4).GetCell(1).SetCellValue(8000);
            int j = 0, l = 0;
            #region 开始循环比对Excel中的每行的库存以及申请数量
            for (int i = 0; i < dgv1.RowCount; i++)
            {
                string partno     = dgv1.Rows[i].Cells[4].Value.ToString();
                string Project_id = string.Empty;
                Project_id = dgv1.Rows[i].Cells["Column1"].Value.ToString();
                ProjectId  = project.FindERPID(Project_id);
                if (!string.IsNullOrEmpty(partno))
                {
                    if (partno.Length < 7)
                    {
                        partno = "0" + partno;
                    }

                    int           tt = j + 1;
                    string        partname, unitname;
                    InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site);
                    if (invpartnew != null)
                    {
                        partname = invpartnew.description;
                        unitname = invpartnew.unit_meas;
                    }
                    else
                    {
                        MessageBox.Show("第" + i + "行ERP中无此材料编码");
                        return;
                    }
                    //DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value);
                    //string reqreason = dgv1.Rows[i].Cells[4].Value.ToString();
                    string reqreason = "1001";
                    string preQty    = dgv1.Rows[i].Cells[6].Value.ToString();
                    string purpose   = dgv1.Rows[i].Cells["Column9"].Value.ToString();
                    string remark    = dgv1.Rows[i].Cells["图纸号"].Value.ToString();
                    Str_Discipline = dgv1.Rows[i].Cells[3].Value.ToString();
                    string        replaceno = "";
                    InventoryPart invpart = InventoryPart.GetRequiredqty(Site, partno, ProjectId);
                    decimal       left_reqqty = 0, reserved_qty = 0;
                    if (invpart != null)
                    {
                        left_reqqty  = Convert.ToDecimal(invpart.qty_reserved);
                        reserved_qty = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_issued);
                    }
                    if (!string.IsNullOrEmpty(purpose))
                    {
                        Str_Area = ProjectBlock.GetAreaByBlock(purpose, ProjectId, Site);
                    }
                    decimal needqty = Convert.ToDecimal(preQty);
                    #region 如果数量不够则考虑替代码的库存以及申请情况
                    if (Convert.ToDecimal(preQty) > left_reqqty + reserved_qty)
                    {
                        #region 先将标准码数量写入
                        if (left_reqqty + reserved_qty > 0)
                        {
                            string meo_no = GetPartMEONO(partno, preQty);
                            sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString());
                            sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId);
                            sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area);
                            sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX);
                            sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline);
                            sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName);
                            sheet1.GetRow(j + 5).GetCell(6).SetCellValue(partno);
                            sheet1.GetRow(j + 5).GetCell(7).SetCellValue(partname);
                            sheet1.GetRow(j + 5).GetCell(9).SetCellValue((left_reqqty + reserved_qty).ToString());
                            sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname);
                            sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no);
                            sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason);
                            sheet1.GetRow(j + 5).GetCell(17).SetCellValue(replaceno);
                            sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark);
                            sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose);
                            j++;
                        }
                        #endregion
                        needqty = Convert.ToDecimal(preQty) - left_reqqty - reserved_qty;

                        #region 替代码的库存数量以及需求数量比对
                        DataSet ReplaceDS = Ration.QueryPartRationList("select replace_no,part_description from mm_part_standard_tab where part_no ='" + partno + "'");
                        if (ReplaceDS != null)
                        {
                            int p = ReplaceDS.Tables[0].Rows.Count;
                            for (int k = 0; k < p; k++)
                            {
                                string        ReplaceNo = ReplaceDS.Tables[0].Rows[k][0].ToString();
                                string        ReplaceDesc = ReplaceDS.Tables[0].Rows[k][1].ToString();
                                InventoryPart invparttemp = InventoryPart.GetRequiredqty(Site, ReplaceNo, ProjectId);
                                decimal       temp_left_reqqty = 0, temp_reserved_qty = 0;
                                if (invparttemp != null)
                                {
                                    temp_left_reqqty  = Convert.ToDecimal(invparttemp.qty_reserved);
                                    temp_reserved_qty = Convert.ToDecimal(invparttemp.qty_onhand) - Convert.ToDecimal(invparttemp.qty_issued);
                                    if (temp_left_reqqty + temp_reserved_qty > 0)
                                    {
                                        #region 此替代码数量仍然不够
                                        if (Convert.ToDecimal(needqty) > temp_left_reqqty + temp_reserved_qty)
                                        {
                                            replaceno = replaceno + ReplaceNo + ";";
                                            needqty   = needqty - temp_left_reqqty - temp_reserved_qty;
                                            string meo_no = GetPartMEONO(ReplaceNo, (temp_left_reqqty + temp_reserved_qty).ToString());
                                            sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString());
                                            sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId);
                                            sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area);
                                            sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX);
                                            sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline);
                                            sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName);
                                            sheet1.GetRow(j + 5).GetCell(6).SetCellValue(ReplaceNo);
                                            sheet1.GetRow(j + 5).GetCell(7).SetCellValue(ReplaceDesc);
                                            sheet1.GetRow(j + 5).GetCell(9).SetCellValue((temp_left_reqqty + temp_reserved_qty).ToString());
                                            sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname);
                                            sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no);
                                            sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason);
                                            sheet1.GetRow(j + 5).GetCell(17).SetCellValue(partno);
                                            sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark);
                                            sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose);
                                            j++;
                                        }
                                        #endregion
                                        #region 替代码数量可以满足则跳出循环
                                        else
                                        {
                                            replaceno = replaceno + ReplaceNo + ";";
                                            string meo_no = GetPartMEONO(ReplaceNo, needqty.ToString());
                                            sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString());
                                            sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId);
                                            sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area);
                                            sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX);
                                            sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline);
                                            sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName);
                                            sheet1.GetRow(j + 5).GetCell(6).SetCellValue(ReplaceNo);
                                            sheet1.GetRow(j + 5).GetCell(7).SetCellValue(ReplaceDesc);
                                            sheet1.GetRow(j + 5).GetCell(9).SetCellValue(needqty.ToString());
                                            sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname);
                                            sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no);
                                            sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason);
                                            sheet1.GetRow(j + 5).GetCell(17).SetCellValue(partno);
                                            sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark);
                                            sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose);
                                            j++;
                                            needqty = 0;

                                            break;
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion
                    #region 如果本身库存以及申请数量足够 直接写入MEO号以及申请数量
                    else
                    {
                        needqty = 0;

                        string meo_no = GetPartMEONO(partno, preQty);
                        sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString());
                        sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId);
                        sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area);
                        sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX);
                        sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline);
                        sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName);
                        sheet1.GetRow(j + 5).GetCell(6).SetCellValue(partno);
                        sheet1.GetRow(j + 5).GetCell(7).SetCellValue(partname);
                        sheet1.GetRow(j + 5).GetCell(9).SetCellValue(preQty);
                        sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname);
                        sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no);
                        sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason);
                        sheet1.GetRow(j + 5).GetCell(17).SetCellValue(replaceno);
                        sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark);
                        sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose);
                        j++;
                    }

                    #endregion
                }
            }
            #endregion
            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;
            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
            //sheet1.GetRow(1).GetCell(1).SetCellValue(200200);
            //sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            //sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            //sheet1.GetRow(4).GetCell(1).SetCellValue(8000);

            try
            {
                WriteToFile(appdir + "\\导出的标准MSS格式\\" + "标准MSSList.xls");
                //WriteToFile(appdir + "\\导出的标准MSS格式\\" + "不足材料列表.xls");
                //MessageBox.Show("导出的标准MSS格式MSSList.xls和不足材料列表" + "成功!", "提示消息");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #region  足MSS的材料信息
            InitializeWorkbook(@appdir + "Template\\不足项目MSS明细表.xls");
            ISheet sheet2 = hssfworkbook.GetSheet("MSS明细表");
            for (int i = 0; i < dgv1.RowCount; i++)
            {
                string partno = dgv1.Rows[i].Cells[4].Value.ToString();
                if (!string.IsNullOrEmpty(partno))
                {
                    string partname, unitname;
                    if (partno.Length < 7)
                    {
                        partno = "0" + partno;
                    }
                    InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site);
                    if (invpartnew != null)
                    {
                        partname = invpartnew.description;
                        unitname = invpartnew.unit_meas;
                    }
                    else
                    {
                        MessageBox.Show("第" + i + "行ERP中无此材料编码");
                        return;
                    }
                    //DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value);
                    string reqreason = "1001";
                    string preQty    = dgv1.Rows[i].Cells[6].Value.ToString();
                    string purpose   = dgv1.Rows[i].Cells["Column9"].Value.ToString();
                    string remark    = dgv1.Rows[i].Cells["图纸号"].Value.ToString();
                    Str_Discipline = dgv1.Rows[i].Cells[3].Value.ToString();
                    string        replaceno = "";
                    InventoryPart invpart = InventoryPart.GetRequiredqty(Site, partno, ProjectId);
                    decimal       left_reqqty = 0, reserved_qty = 0;
                    if (invpart != null)
                    {
                        left_reqqty  = Convert.ToDecimal(invpart.qty_reserved);
                        reserved_qty = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_issued);
                    }
                    decimal needqty = Convert.ToDecimal(preQty);
                    if (Convert.ToDecimal(preQty) > left_reqqty + reserved_qty)
                    {
                        needqty = Convert.ToDecimal(preQty) - left_reqqty - reserved_qty;
                        //decimal replaceqty = 0;

                        DataSet ReplaceDS = Ration.QueryPartRationList("select replace_no from mm_part_standard_tab where part_no ='" + partno + "'");
                        if (ReplaceDS != null)
                        {
                            int p = ReplaceDS.Tables[0].Rows.Count;
                            for (int k = 0; k < p; k++)
                            {
                                string        ReplaceNo = ReplaceDS.Tables[0].Rows[k][0].ToString();
                                InventoryPart invparttemp = InventoryPart.GetRequiredqty(Site, ReplaceNo, ProjectId);
                                decimal       temp_left_reqqty = 0, temp_reserved_qty = 0;
                                if (invparttemp != null)
                                {
                                    temp_left_reqqty  = Convert.ToDecimal(invparttemp.qty_reserved);
                                    temp_reserved_qty = Convert.ToDecimal(invparttemp.qty_onhand) - Convert.ToDecimal(invparttemp.qty_issued);
                                    if (temp_left_reqqty + temp_reserved_qty > 0)
                                    {
                                        if (Convert.ToDecimal(needqty) > temp_left_reqqty + temp_reserved_qty)
                                        {
                                            replaceno = replaceno + ReplaceNo + ";";
                                            needqty   = needqty - temp_left_reqqty - temp_reserved_qty;
                                        }
                                        else
                                        {
                                            replaceno = replaceno + ReplaceNo + ";";
                                            needqty   = 0;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        //if (i + 5 > 10)
                        //  sheet1.CreateRow(i + 5);
                    }
                    else
                    {
                        needqty = 0;
                    }
                    if (needqty == 0)
                    {
                    }
                    else
                    {
                        int tt = l + 1;
                        sheet2.GetRow(l + 5).GetCell(0).SetCellValue(tt.ToString());
                        sheet2.GetRow(l + 5).GetCell(1).SetCellValue(ProjectId);
                        sheet2.GetRow(l + 5).GetCell(2).SetCellValue(Str_Area);
                        sheet2.GetRow(l + 5).GetCell(3).SetCellValue(Str_FX);
                        sheet2.GetRow(l + 5).GetCell(4).SetCellValue(Str_Discipline);
                        sheet2.GetRow(l + 5).GetCell(5).SetCellValue(ActivityName);
                        sheet2.GetRow(l + 5).GetCell(6).SetCellValue(partno);
                        sheet2.GetRow(l + 5).GetCell(7).SetCellValue(partname);
                        sheet2.GetRow(l + 5).GetCell(9).SetCellValue(needqty.ToString());
                        sheet2.GetRow(l + 5).GetCell(10).SetCellValue(unitname);
                        //sheet2.GetRow(j + 5).GetCell(11).SetCellValue(reqdate);
                        sheet2.GetRow(l + 5).GetCell(12).SetCellValue(reqreason);
                        //sheet2.GetRow(j + 5).GetCell(13).SetCellValue(reqreason);
                        sheet2.GetRow(l + 5).GetCell(15).SetCellValue(remark);
                        sheet2.GetRow(l + 5).GetCell(16).SetCellValue(purpose);
                        //sheet1.GetRow(i + 5).GetCell(17).SetCellValue(replaceno);
                        //if (i + 5 > 14)
                        //    sheet2.CreateRow(j + 6);
                        l++;
                    }
                }
            }
            sheet2.ForceFormulaRecalculation = true;
            #endregion
            try
            {
                //WriteToFile(appdir + "\\导出的标准MSS格式\\" + "标准MSSList.xls");
                WriteToFile(appdir + "\\导出的标准MSS格式\\" + "不足材料列表.xls");
                MessageBox.Show("导出的标准MSS格式MSSList.xls和不足材料列表" + "成功!", "提示消息");
                System.Diagnostics.Process.Start("explorer.exe", appdir + "导出的标准MSS格式");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public async Task <List <Ration> > CalcRations(int userId)
        {
            var user = await context.Users
                       .Include(k => k.KormUsers).ThenInclude(k => k.Korm)
                       .FirstOrDefaultAsync(u => u.Id == userId);

            var catalogIndexFoods = await context.CatalogIndexFoods.ToListAsync();

            int n     = catalogIndexFoods.Count() + 1;
            int m     = user.KormUsers.Count() + 1;
            var table = new double[n, m];

            for (int i = 0; i < n - 1; i++)
            {
                table[i, 0] = catalogIndexFoods[i].Limitation * -1;
                var charactereizations = context.CharacterizationIndexFoods
                                         .Include(k => k.Korm)
                                         .Include(c => c.CatalogIndexFood)
                                         .Where(c => c.CatalogIndexFoodId == catalogIndexFoods[i].Id).ToList();
                for (int j = 1; j < m; j++)
                {
                    table[i, j] = Math.Abs(charactereizations[j - 1].Value) * -1;
                }
            }

            for (int i = 1; i < m; i++)
            {
                double c = user.KormUsers[i - 1].Korm.Price * -1;
                table[n - 1, i] = c;
            }
            table[n - 1, 0] = 0;
            var result = new double[user.KormUsers.Count()];

            double[,] table_result;
            Simplex S = new Simplex(table);

            table_result = S.Calculate(result);
            var taskRation = new TaskRation
            {
                User    = user,
                UserId  = user.Id,
                Rations = new List <Ration>()
            };

            for (int i = 0; i < user.KormUsers.Count; i++)
            {
                if (result[i] == 0)
                {
                    break;
                }
                var ration = new Ration
                {
                    KormId = user.KormUsers[i].KormId,
                    Value  = result[i]
                };
                taskRation.Rations.Add(ration);
            }
            await context.TaskRations.AddAsync(taskRation);

            await context.SaveChangesAsync();

            return(taskRation.Rations.ToList());
        }
Beispiel #4
0
        private void btn_del_Click(object sender, EventArgs e)
        {
            if (dgv1.RowCount < 1)
            {
                return;
            }
            InitializeWorkbook(@"Template/项目MSS明细表.xls");
            ISheet sheet1 = hssfworkbook.GetSheet("MSS明细表");

            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
            //sheet1.GetRow(1).GetCell(1).SetCellValue(200200);
            //sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            //sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            //sheet1.GetRow(4).GetCell(1).SetCellValue(8000);
            for (int i = 0; i < dgv1.RowCount; i++)
            {
                string   partno     = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                string   partname   = dgv1.Rows[i].Cells["零件描述"].Value.ToString();
                DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value);
                string   reqdate    = reqdatestr.ToString("yyyy-MM-dd");
                string   reqreason  = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
                string   unitname   = dgv1.Rows[i].Cells["单位"].Value.ToString();
                string   preQty     = dgv1.Rows[i].Cells["需求数量"].Value.ToString();
                string   remark     = "";
                if (dgv1.Rows[i].Cells["备注"].Value != null)
                {
                    remark = dgv1.Rows[i].Cells["备注"].Value.ToString();
                }
                sheet1.GetRow(i + 5).GetCell(0).SetCellValue(i + 1);
                sheet1.GetRow(i + 5).GetCell(1).SetCellValue(ProjectId);
                sheet1.GetRow(i + 5).GetCell(2).SetCellValue(Str_Area);
                sheet1.GetRow(i + 5).GetCell(3).SetCellValue(Str_FX);
                sheet1.GetRow(i + 5).GetCell(4).SetCellValue(Str_Discipline);
                sheet1.GetRow(i + 5).GetCell(5).SetCellValue(ActivityName);
                sheet1.GetRow(i + 5).GetCell(6).SetCellValue(partno);
                sheet1.GetRow(i + 5).GetCell(7).SetCellValue(partname);
                sheet1.GetRow(i + 5).GetCell(9).SetCellValue(preQty);
                sheet1.GetRow(i + 5).GetCell(10).SetCellValue(unitname);
                //sheet1.GetRow(i + 5).GetCell(11).SetCellValue(reqdate);
                sheet1.GetRow(i + 5).GetCell(12).SetCellValue(reqreason);
                sheet1.GetRow(i + 5).GetCell(13).SetCellValue(reqreason);
                //sheet1.GetRow(i + 5).GetCell(14).SetCellValue(meolist.INFORMATION);
                sheet1.GetRow(i + 5).GetCell(15).SetCellValue(remark);
                if (i + 5 > 14)
                {
                    sheet1.CreateRow(i + 6);
                }
                #region 循环保存数据
                string Rationid = dgv1.Rows[i].Cells["Ration_id"].Value.ToString();
                Ration.UpdateMSSState(Rationid, 5);
                #endregion
            }

            //Force excel to recalculate all the formula while open
            sheet1.ForceFormulaRecalculation = true;

            try
            {
                WriteToFile("MSS导出/" + "MSSList.xls");
                //MessageBox.Show("MSSList.xls" + "导出成功!", "提示消息");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            InitializeWorkbook(@"Template/项目MEO明细表.xls");
            ISheet sheet2 = hssfworkbook.GetSheet("MEO明细表");
            //create cell on rows, since rows do already exist,it's not necessary to create rows again.
            //sheet1.GetRow(1).GetCell(1).SetCellValue(200200);
            //sheet1.GetRow(2).GetCell(1).SetCellValue(300);
            //sheet1.GetRow(3).GetCell(1).SetCellValue(500050);
            //sheet1.GetRow(4).GetCell(1).SetCellValue(8000);
            int j = 0;
            for (int i = 0; i < dgv1.RowCount; i++)
            {
                string  preQty       = dgv1.Rows[i].Cells["需求数量"].Value.ToString();
                decimal left_reqqty  = Convert.ToDecimal(dgv1.Rows[i].Cells["left_qty"].Value.ToString());
                decimal reserved_qty = Convert.ToDecimal(dgv1.Rows[i].Cells["reserved_qty"].Value.ToString());

                if (Convert.ToDecimal(preQty) > left_reqqty + reserved_qty)
                {
                    string   partno     = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                    string   partname   = dgv1.Rows[i].Cells["零件描述"].Value.ToString();
                    DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value);
                    string   reqdate    = reqdatestr.ToString("yyyy-MM-dd");
                    string   reqreason  = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
                    string   unitname   = dgv1.Rows[i].Cells["单位"].Value.ToString();
                    string   remark     = "";
                    if (dgv1.Rows[i].Cells["备注"].Value != null)
                    {
                        remark = dgv1.Rows[i].Cells["备注"].Value.ToString();
                    }
                    sheet2.GetRow(j + 5).GetCell(0).SetCellValue(i + 1);
                    sheet2.GetRow(j + 5).GetCell(2).SetCellValue(ProjectId);
                    sheet2.GetRow(j + 5).GetCell(3).SetCellValue(Str_Area);
                    sheet2.GetRow(j + 5).GetCell(4).SetCellValue(Str_FX);
                    sheet2.GetRow(j + 5).GetCell(5).SetCellValue(Str_Discipline);
                    sheet2.GetRow(j + 5).GetCell(6).SetCellValue(ActivityName);
                    sheet2.GetRow(j + 5).GetCell(7).SetCellValue(partno);
                    sheet2.GetRow(j + 5).GetCell(8).SetCellValue(partname);
                    sheet2.GetRow(j + 5).GetCell(9).SetCellValue(preQty);
                    sheet2.GetRow(j + 5).GetCell(10).SetCellValue(unitname);
                    sheet2.GetRow(j + 5).GetCell(11).SetCellValue(reqdate);
                    sheet2.GetRow(j + 5).GetCell(12).SetCellValue(reqreason);
                    sheet2.GetRow(j + 5).GetCell(13).SetCellValue(reqreason);
                    //sheet1.GetRow(i + 5).GetCell(14).SetCellValue(meolist.INFORMATION);
                    sheet2.GetRow(j + 5).GetCell(15).SetCellValue(remark);
                    if (i + 5 > 14)
                    {
                        sheet2.CreateRow(j + 6);
                    }
                    j++;
                }
            }

            //Force excel to recalculate all the formula while open
            sheet2.ForceFormulaRecalculation = true;

            try
            {
                WriteToFile("MSS导出/" + "不足材料列表.xls");
                MessageBox.Show("MSSList.xls和不足材料列表.xls" + "导出成功!", "提示消息");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #5
0
        public void listviewBind(string sql)
        {
            this.dgv1.AutoGenerateColumns = false;
            this.dgv1.Rows.Clear();
            DataSet  ds = Ration.QueryPartRationList(sql);
            DataView dv = ds.Tables[0].DefaultView;
            int      i  = 1;

            foreach (DataRow dr in dv.Table.Rows)
            {
                string          partno = dr[1].ToString();
                DataGridViewRow r      = new DataGridViewRow();
                r.CreateCells(dgv1);
                //行号
                r.Cells[0].Value = i;
                //Ration_id
                r.Cells[1].Value = dr[0].ToString();
                //区域,分项,专业,种类
                //Block与 区域对应表;取得区域
                r.Cells[2].Value = dr[11].ToString();
                //根据ERP Code来区分是材料还是设备,取得分项
                r.Cells[3].Value = dr[12].ToString();
                //专业可以让设计员自己填写或者默认
                r.Cells[4].Value = dr[13].ToString();
                //可以根据ERP Code来确定 材料种类
                r.Cells[5].Value = dr[14].ToString();

                //part_id零件号
                r.Cells[6].Value = partno;
                //part_name零件描述
                r.Cells[7].Value = dr[2].ToString();
                if (partno != string.Empty && partno != null)
                {
                    //InventoryPart invpart = InventoryPart.GetRequiredqty(cSite, partno, ProjectId);
                    //if (invpart != null)
                    //{
                    //    //总申请数量
                    //    r.Cells[8].Value = invpart.qty_onhand;
                    //    //已下发申请数量
                    //    r.Cells[9].Value = invpart.qty_issued;
                    //    //余下申请数量
                    //    r.Cells[10].Value = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_issued);
                    //    //可用项目预留数量
                    //    r.Cells[11].Value = invpart.qty_reserved;
                    //}
                }
                //需求数量
                r.Cells[12].Value = dr[3].ToString();
                //单位
                r.Cells[13].Value = dr[4].ToString();
                //ERPMEONO
                r.Cells[14].Value = dr[5].ToString();
                //图纸号
                r.Cells[15].Value = dr[6].ToString();
                //分段号
                r.Cells[16].Value = dr[7].ToString();
                //需求日期
                r.Cells[17].Value = dr[8].ToString();
                //备注
                r.Cells[18].Value = dr[9].ToString();
                //需求原因
                r.Cells[20].Value = dr[10].ToString();



                this.dgv1.Rows.Add(r);
                i++;
            }
        }
Beispiel #6
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (dgv1.RowCount < 1)
            {
                return;
            }

            if (ProjectId == string.Empty)
            {
                MessageBox.Show("请选择项目");
                return;
            }

            int rowcou = dgv1.RowCount;

            if (rowcou == 0)
            {
                MessageBox.Show("请选择所要下发的材料", "操作提示");
                return;
            }

            rowcou = dgv1.RowCount;

            //for (int i = 0; i < rowcou; i++)
            //{

            //    if (dgv1.Rows[i].Cells["序号"].Value == null)
            //    {

            //        MessageBox.Show("第" + (i + 1) + "行请填写材料", "提示");
            //        return;
            //    }


            //}
            SetRowNo();
            try
            {
                for (int i = 0; i < rowcou; i++)
                {
                    #region 检查必填项以及数据的合法性
                    string rowid = dgv1.Rows[i].Cells["行"].Value.ToString();
                    if (dgv1.Rows[i].Cells["需求数量"].Value != null)
                    {
                        if (!BaseClass.validateNum(dgv1.Rows[i].Cells["需求数量"].Value.ToString().Trim()))
                        {
                            MessageBox.Show("第 " + rowid + " 行需求数量请填写数字", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                        if (dgv1.Rows[i].Cells["需求数量"].Value.ToString().Trim().Contains("-"))
                        {
                            MessageBox.Show("第 " + rowid + " 行需求数量为负,请检查", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求数量", "提示");
                        //dgv1.Rows[i].Selected = true;
                        dgv1.CurrentCell = dgv1.Rows[i].Cells["需求数量"];
                        return;
                    }

                    //if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                    //{
                    //    if (!BaseClass.validateNum(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString().Trim()))
                    //    {
                    //        MessageBox.Show("第 " + rowid + " 行MEO号请填写数字", "提示");
                    //        dgv1.Rows[i].Selected = true;
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    //if (MEOID != "0")
                    //    //{
                    //    //    MessageBox.Show("第 " + rowid + " 行请填写MEO号", "提示");
                    //    //    //dgv1.Rows[i].Selected = true;
                    //    //    dgv1.CurrentCell = dgv1.Rows[i].Cells["MEO_ERP"];
                    //    //    return;
                    //    //}
                    //}

                    if (dgv1.Rows[i].Cells["需求日期"].Value == null)
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求日期", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                    //if (dgv1.Rows[i].Cells["需求日期"].Value != null)
                    //{
                    //    if (Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value.ToString()) < DateTime.Today)
                    //    {
                    //        MessageBox.Show("第 " + rowid + " 行需求日期不能小于当前日期", "提示");
                    //        dgv1.Rows[i].Selected = true;
                    //        return;
                    //    }
                    //}
                    if (dgv1.Rows[i].Cells["需求原因"].Value == null)
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求原因", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }

                    if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                    {
                        string partno = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                        if (MEOsub.meomssExistERP(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString(), partno) == 0)
                        {
                            MessageBox.Show("第 " + rowid + " 行ERP中的MEO号不存在", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < rowcou; i++)
                {
                    #region 循环保存数据
                    string   Rationid   = dgv1.Rows[i].Cells["Ration_id"].Value.ToString();
                    string   contractno = cmb_site.SelectedValue.ToString();
                    string   Partno     = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                    Decimal  Reqqty     = Decimal.Parse(dgv1.Rows[i].Cells["需求数量"].Value.ToString());
                    DateTime ReqDate    = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value.ToString());
                    //string purpose = txt_purpose.Text.Trim().ToString();
                    string blockId    = cmb_block.SelectedValue.ToString();
                    string ReasonCode = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
                    //string DesignCode = txt_designcode.Text.Trim().ToString();
                    string ReqNo  = dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString();
                    string remark = dgv1.Rows[i].Cells["备注"].Value.ToString();
                    //string isInventory = chb_useInv.Checked == true ? "是" : "否";
                    string Partname = dgv1.Rows[i].Cells["零件描述"].Value.ToString();
                    string zyname   = dgv1.Rows[i].Cells["dt_zy"].Value.ToString();
                    string qyname   = dgv1.Rows[i].Cells["dt_qy"].Value.ToString();
                    string fxname   = dgv1.Rows[i].Cells["dt_fx"].Value.ToString();
                    string zlname   = dgv1.Rows[i].Cells["dt_zl"].Value.ToString();
                    Ration mp       = new Ration();
                    mp.PROJECT_ID  = ProjectId;
                    mp.RATION_ID   = Convert.ToInt32(Rationid);
                    mp.PART_NO     = Partno;
                    mp.ISSUED_QTY  = decimal.Round(Reqqty, 2);
                    mp.ISSUED_DATE = ReqDate;
                    //mp.IF_INVENTORY = isInventory;
                    //mp.PURPOSE = purpose;
                    mp.BLOCK_ID    = blockId;
                    mp.REASON_CODE = ReasonCode;
                    //mp.DESIGN_CODE = DesignCode;
                    mp.REMARK          = remark;
                    mp.INFORMATION     = remark;
                    mp.CONTRACT        = contractno;
                    mp.CREATER         = User.cur_user;
                    mp.PART_NAME       = Partname;
                    mp.ECPROJECTID     = ecprojectid;
                    mp.PART_ZONE       = qyname;
                    mp.PART_FX         = fxname;
                    mp.PART_DISCIPLINE = zyname;
                    mp.PART_TYPE       = zlname;
                    XmlOper.setXML("Block", blockId);
                    if (Rationid != "0")
                    {
                        //mp.RATION_ID = Convert.ToInt32(lbl_rationid.Text);
                        int n = mp.Update();
                    }
                    else
                    {
                        int n = mp.Add();
                    }
                    #endregion
                }
                MessageBox.Show("保存成功!!!");
            }
            catch (Exception err)
            {
                MessageBox.Show("错误原因:" + err.Message, "错误提示信息",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //    QuerydataBind();
        }
        /*public WaiterWindow()
         * {
         *  InitializeComponent();
         *  bl = new BussinesLogic();
         *  List<Ration> rations = bl.GetAllRations();
         *  List<Order> orders = bl.GetAllOrders();
         * }*/

        public void UpdateRation(Ration ration)
        {
            bl.Update(ration);
        }
Beispiel #8
0
 public bool EditRation(Ration ration)
 {
     _unitOfWork.RationRepository.Edit(ration);
     _unitOfWork.Save();
     return(true);
 }
Beispiel #9
0
 public bool AddRation(Ration ration)
 {
     _unitOfWork.RationRepository.Add(ration);
     _unitOfWork.Save();
     return(true);
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Ви зайшли в програму по управлiнню зоопарком. Можете тут нагодувати тварин, які голодні");
            Console.WriteLine("Котра зараз година?");
            DateTimeOffset time      = DateTimeOffset.Now;
            DateTimeOffset timeutc   = DateTimeOffset.UtcNow;
            int            hourUtc   = time.Hour - timeutc.Hour;
            int            minuteUtc = time.Minute - timeutc.Minute;

            Console.WriteLine(time.Hour + ":" + time.Minute + ", UTC : " + 2 + ":" + minuteUtc);

            Aviary aviaryNumber1 = new Aviary(1, ListOfAnimals.Jaguars);

            Base.Aviaries.Add(aviaryNumber1.Id, aviaryNumber1);
            Aviary aviaryNumber2 = new Aviary(2, ListOfAnimals.Tigers);

            Base.Aviaries.Add(aviaryNumber2.Id, aviaryNumber2);


            Food meat = new Food("М'ясо", 39, ListOfAnimals.Jaguars);

            Base.Foods.Add(meat);


            Ration forTigers = new Ration(meat, ListOfAnimals.Tigers);

            Base.Rations.Add(forTigers.Id, forTigers);
            Ration forJaguars = new Ration(meat, ListOfAnimals.Jaguars);

            Base.Rations.Add(forJaguars.Id, forJaguars);


            //І'мя, cкільки років, який вольєр, який тип тварин, коли їсть вранці, коли їсть вечером, тип живлення, що саме, чи голодна
            Animal animalZebra = new Animal(Guid.NewGuid(),
                                            "Майя",
                                            new DateTimeOffset(2000, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0)),
                                            (int)((time - new DateTimeOffset(2000, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0))).TotalDays / 365),
                                            TypeOfAnimals.Mammals,
                                            TypeOfAnimalsOnTutrion.Herbivores,
                                            ListOfAnimals.Tigers);

            Base.Animals.Add(animalZebra.Id, animalZebra);

            Animal animalSinica = new Animal(Guid.NewGuid(),
                                             "Рябуха",
                                             new DateTimeOffset(2010, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0)),
                                             (int)((time - new DateTimeOffset(2010, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0))).TotalDays / 365),
                                             TypeOfAnimals.Mammals,
                                             TypeOfAnimalsOnTutrion.Omnivorous,
                                             ListOfAnimals.Jaguars
                                             );

            Base.Animals.Add(animalSinica.Id, animalSinica);

            Animal animalDog = new Animal(Guid.NewGuid(),
                                          "Жук",
                                          new DateTimeOffset(2005, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0)),
                                          (int)((time - new DateTimeOffset(2005, 11, 4, 11, 02, 55, new TimeSpan(hourUtc, minuteUtc, 0))).TotalDays / 356),
                                          TypeOfAnimals.Mammals,
                                          TypeOfAnimalsOnTutrion.MeatEaters,
                                          ListOfAnimals.Jaguars);

            Base.Animals.Add(animalDog.Id, animalDog);

            //CheckedType.CheckedTypeOfAnimals();
            foreach (KeyValuePair <Guid, Aviary> keyValue in Base.Aviaries)
            {
                foreach (Animal animal in keyValue.Value.Animals)
                {
                    TypeOfAnimals animal2;
                    int           number = 0;
                    number++;

                    if (number != keyValue.Value.Animals.Count)
                    {
                        animal2 = keyValue.Value.Animals.ElementAt(number).TypeOfAnimals;

                        if (animal2 != animal.TypeOfAnimals)
                        {
                            Console.WriteLine("У вас в одному вольєрі живуть різні типи тварин, перевірте у своїх вольєрах тварин!");
                        }
                    }
                }
            }

            // ChangeHungry.ChangeHungryOfAnimal();

            foreach (KeyValuePair <Guid, Animal> keyValue in Base.Animals)
            {
                Animal animal = keyValue.Value;
                // Console.WriteLine(keyValue.Value.Name);



                switch (keyValue.Value.ListAnimals)
                {
                case ListOfAnimals.Tigers:
                {
                    switch (keyValue.Value.Age)
                    {
                    case int n when(keyValue.Value.Age <= 2):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 1;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 11, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 15, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time4 = new DateTimeOffset(time.Year, time.Month, time.Day, 16, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time5 = new DateTimeOffset(time.Year, time.Month, time.Day, 21, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                ration.Eating.Add(time3);
                                ration.Eating.Add(time4);
                                ration.Eating.Add(time5);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 6;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 6;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age > 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 2;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 18, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }

                    break;
                }

                case ListOfAnimals.Jaguars:
                {
                    switch (keyValue.Value.Age)
                    {
                    case int n when(keyValue.Value.Age <= 1):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 11, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 15, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time4 = new DateTimeOffset(time.Year, time.Month, time.Day, 16, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time5 = new DateTimeOffset(time.Year, time.Month, time.Day, 21, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                ration.Eating.Add(time3);
                                ration.Eating.Add(time4);
                                ration.Eating.Add(time5);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 5):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 2;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 10, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 15, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time4 = new DateTimeOffset(time.Year, time.Month, time.Day, 19, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                ration.Eating.Add(time3);
                                ration.Eating.Add(time4);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 3;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 1;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age > 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));

                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 22, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);

                                ration.Eating.Add(time3);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }

                    break;
                }

                case ListOfAnimals.Delfins:
                {
                    switch (keyValue.Value.Age)
                    {
                    case int n when(keyValue.Value.Age <= 2):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 1;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 11, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 15, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time4 = new DateTimeOffset(time.Year, time.Month, time.Day, 16, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time5 = new DateTimeOffset(time.Year, time.Month, time.Day, 21, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                ration.Eating.Add(time3);
                                ration.Eating.Add(time4);
                                ration.Eating.Add(time5);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 5):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 6;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 4;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 5):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 2;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 4;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));

                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 19, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);

                                ration.Eating.Add(time3);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age > 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 4;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));

                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 19, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);

                                ration.Eating.Add(time3);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }

                    break;
                }

                case ListOfAnimals.Zebras:
                {
                    switch (keyValue.Value.Age)
                    {
                    case int n when(keyValue.Value.Age <= 3):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 11, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 15, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time4 = new DateTimeOffset(time.Year, time.Month, time.Day, 16, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time5 = new DateTimeOffset(time.Year, time.Month, time.Day, 21, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                ration.Eating.Add(time3);
                                ration.Eating.Add(time4);
                                ration.Eating.Add(time5);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 5):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 2;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 17, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age <= 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 1;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 4;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 7, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time2 = new DateTimeOffset(time.Year, time.Month, time.Day, 14, 0, 00, new TimeSpan(2, 0, 0));
                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 19, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);
                                ration.Eating.Add(time2);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case int n when(keyValue.Value.Age > 10):
                    {
                        foreach (Ration ration in Base.Rations.Values)
                        {
                            if (animal.ListAnimals == ration.ListAnimals)
                            {
                                int weight = ration.WeightPortion;
                                weight = 4;
                                ration.Weight(weight);
                                int coef = ration.Coefficient;
                                coef = 3;
                                ration.Coef(coef);
                                DateTimeOffset time1 = new DateTimeOffset(time.Year, time.Month, time.Day, 9, 0, 00, new TimeSpan(2, 0, 0));

                                DateTimeOffset time3 = new DateTimeOffset(time.Year, time.Month, time.Day, 19, 0, 00, new TimeSpan(2, 0, 0));
                                ration.Eating.Add(time1);

                                ration.Eating.Add(time3);
                                foreach (DateTimeOffset t in ration.Eating)
                                {
                                    if (time.Hour > t.Hour + weight * coef)
                                    {
                                        animal.ChangeHungry(true);
                                    }
                                    else
                                    {
                                        animal.ChangeHungry(false);
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }

                    break;
                }
                }
            }


            foreach (KeyValuePair <Guid, Aviary> keyValue in Base.Aviaries)
            {
                Console.WriteLine(keyValue.Value.Number);
                foreach (Animal animal in keyValue.Value.Animals)
                {
                    if (animal.ListAnimals == keyValue.Value.ListAnimals)
                    {
                        Console.WriteLine("Ім'я тварини: " + animal.Name + ", " + "Дата народження: " + animal.YearOfBirth + ", Age: " + animal.Age + ", Вольєр " + keyValue.Value.Number + "  " + animal.ListAnimals + "Чи голодна тварина? " + animal.Hungry + ", " + "Яка тварина? " + animal.TypeOfAnimalsOnTutrion + ", Раціон : ");
                    }
                }
            }

            Console.WriteLine("Вивести список голодних тварин?");
            string answer = Console.ReadLine();

            if (answer == "y")
            {
                foreach (KeyValuePair <Guid, Animal> animal in Base.Animals)
                {
                    bool r = animal.Value.Hungry;
                    if (r == true)
                    {
                        HungryAnimal.Add(animal.Value);
                    }
                }
            }
            foreach (Animal animal in HungryAnimal)
            {
                Console.WriteLine("Список голодних тварин: " + animal.Name + animal.ListAnimals);
            }


            if (HungryAnimal.Count == 0)
            {
                Console.WriteLine("У вас немає голодних тварин");
            }
            else
            {
                for (int i = HungryAnimal.Count; i > 0; i--)
                {
                    int count = HungryAnimal.Count;
                    Console.WriteLine(count);

                    for (int l = count; l > 0; l--)
                    {
                        Console.WriteLine("Ваші запаси їжї");

                        foreach (Food food in Base.Foods)
                        {
                            Console.WriteLine(food.Name + " " + food.Weight);
                        }
                    }

                    Console.WriteLine("Ви хочете нагодувати тварин?");
                    string answer3 = Console.ReadLine();
                    if (answer3 == "y")
                    {
                        Console.WriteLine("Кого хочете нагодувати? Введить ім'я :");
                        string answer2 = Console.ReadLine();
                        foreach (KeyValuePair <Guid, Aviary> keyValue in Base.Aviaries)
                        {
                            foreach (Animal animal in keyValue.Value.Animals)
                            {
                                if (animal.Name == answer2)
                                {
                                    bool k = animal.Hungry;
                                    k = false;
                                    HungryAnimal.Remove(animal);
                                    animal.ChangeHungry(k);

                                    foreach (Food food in Base.Foods)
                                    {
                                        foreach (KeyValuePair <Guid, Ration> rat in Base.Rations)
                                        {
                                            if (food.ListAnimals == rat.Value.ListAnimals)
                                            {
                                                int weight = food.Weight;
                                                weight -= rat.Value.WeightPortion;
                                                food.ChangeWeight(weight);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }