Esempio n. 1
0
        public void savedMoney(NormalConsume normalConsume)
        {
            double surplus;
            var    KwM = Kwh_up_Month;

            if (normalConsume.consumeMonth != 0)
            {
                for (double i = normalConsume.rankElectricWorkList.Count; i >= 1; i--)
                {
                    var E = normalConsume.rankElectricWorkList[i];
                    E.UsedWork  = E.usedPrice / E.Price;
                    surplus     = KwM - E.UsedWork;
                    E.SavedWork = surplus >= 0 ? E.UsedWork : KwM;
                    KwM         = surplus;
                    rankElectricWorkPrivate.Add(i, E);
                }
            }
            else
            {
                var keyList = new string[3] {
                    "Cao điểm", "Bình thường", "Thấp điểm"
                };
                foreach (var key in keyList)
                {
                    var E = normalConsume.rankElectricWorkList[key];
                    surplus     = KwM - E.UsedWork;
                    E.SavedWork = surplus >= 0 ? E.UsedWork : KwM;
                    KwM         = surplus;
                    rankElectricWorkPrivate.Add(key, E);
                }
            }

            SurplusWork  = KwM >= 0 ? KwM : 0;
            SurplusPrice = SurplusWork * sellforEVN;
        }
        private void ReadDataExcel(int index)
        {
            try
            {
                rankE = null;
                soGioNangHashtable.Clear();
                rankE = new SortedList <object, rankElectricWork>();

                string path = @Properties.Settings.Default.pathDataExcel;
                using (ExcelPackage MaNS =
                           new ExcelPackage(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    ExcelWorksheet workSheet = MaNS.Workbook.Worksheets[0];

                    for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
                    {
                        soGioNangHashtable.Add(workSheet.Cells[i, 2].Value, workSheet.Cells[i, 3].Value);
                    }


                    workSheet = MaNS.Workbook.Worksheets[index];
                    switch (index)
                    {
                    case 1:
                    {
                        for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
                        {
                            rankElectricWork E = new rankElectricWork();
                            E.Price           = (double)workSheet.Cells[i, 2].Value;
                            E.quantityAllowed = (double)workSheet.Cells[i, 3].Value;
                            rankE.Add(workSheet.Cells[i, 1].Value, E);

                            // rankElectricWorkPrice.Add(, );
                            // rankElectricWorkCount.Add(workSheet.Cells[i, 1].Value, );
                            normalConsume = new NormalConsume()
                            {
                                rankElectricWorkList = rankE
                            };
                        }
                        break;
                    }

                    default:
                        for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
                        {
                            rankElectricWork E = new rankElectricWork();
                            E.Price = (double)workSheet.Cells[i, 2].Value;
                            rankE.Add(workSheet.Cells[i, 1].Value, E);
                            // rankElectricWorkPrice.Add(, );
                            // rankElectricWorkCount.Add(workSheet.Cells[i, 1].Value, );
                            normalConsume = new NormalConsume()
                            {
                                rankElectricWorkList = rankE
                            };
                        }
                        break;
                    }
                    // normalConsume = new NormalConsume(700, 3100, 1000)
                    // normalConsume = new NormalConsume(5000000)
                    // {
                    //     rankElectricWorkList = rankE
                    // };
                }

                khuvucComboBox.ItemsSource = soGioNangHashtable.Keys;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                throw;
            }
        }