Example #1
0
 public void Init()
 {
     totalData = CostingHistoryCSV.GetData(true);
     totalPage = (int)Math.Ceiling((double)totalData.Count / pageSize);
     pageIndex = firstPage;
     UpdatePage();
 }
Example #2
0
        //public CostData()
        //{

        //}

        //Name, Objects, Weight, New, Recycled, Rate, Time, Created, Cost
        public CostData(string[] datas = null, bool isReading = false, int index = 0)
        {
            #region remove code
            //if (isReading)
            //{
            //    if (datas.Length != CostingHistoryCSV.ParamAmount) return;
            //    name = datas[0];
            //    machinename = datas[1];
            //    profilename = datas[2];
            //    objects = datas[3];
            //    objectCount = Convert.ToInt16(objects);
            //    if (objectCount > 1)
            //    {
            //        costObjects = new List<CostObjectData>();
            //    }
            //    weight = datas[4];
            //    newPrice = datas[5];
            //    recycledPrice = datas[6];
            //    rate = datas[7];
            //    time = datas[8];
            //    created = datas[9];
            //    cost = datas[10];
            //}
            #endregion

            //modified code for fixing compatibility issue of old Costing History file.
            if (isReading)
            {
                List <Dictionary <string, string> > record_history = CostingHistoryCSV.BackUp_Records(CostingHistoryCSV.path);
                if (index < record_history.Count)
                {
                    Dictionary <string, string> record = record_history[index];
                    //if (datas.Length == CostingHistoryCSV.ParamAmount) return;
                    name        = record.ContainsKey("Name") ? record["Name"] : "---";
                    profilename = record.ContainsKey("Profile Settings") ? record["Profile Settings"] : "---";
                    machinename = record.ContainsKey("Printer Name") ? record["Printer Name"] : "---";
                    objects     = record.ContainsKey("Objects") ? record["Objects"] : "---";
                    if (objects != "-")
                    {
                        objectCount = Convert.ToInt16(objects);
                    }
                    if (objectCount > 1)
                    {
                        costObjects = new List <CostObjectData>();
                    }
                    weight        = record.ContainsKey("Weight") ? record["Weight"] : "---";
                    newPrice      = record.ContainsKey("New") ? record["New"] : "---";
                    recycledPrice = record.ContainsKey("Recycled") ? record["Recycled"] : "---";
                    rate          = record.ContainsKey("Rate") ? record["Rate"] : "---";
                    time          = record.ContainsKey("Time") ? record["Time"] : "---";
                    created       = record.ContainsKey("Created") ? record["Created"] : "---";
                    cost          = record.ContainsKey("Cost") ? record["Cost"] : "---";
                }
            }
            //<><><>
        }
Example #3
0
 public void RemoveHistory(List <CostData> costDatas)
 {
     foreach (CostData costData in costDatas)
     {
         totalData.Remove(costData);
     }
     totalPage = (int)Math.Ceiling((double)totalData.Count / pageSize);
     UpdatePage();
     CostingHistoryCSV.Save(totalData);
 }
Example #4
0
 public void AddHistory(CostData costData)
 {
     totalData.Insert(0, costData);
     totalPage = (int)Math.Ceiling((double)totalData.Count / pageSize);
     pageIndex = firstPage;
     //lastBtn.Content = totalPage;
     //firstBtn.Content = firstPage;
     UpdatePage();
     CostingHistoryCSV.Save(totalData);
     if (costData.objectCount > 0)
     {
         CostingHistoryCSV.SaveCostDataFor3WL(costData); // this was to create a costing history which append in 3wl File.
     }
 }
Example #5
0
        static public List <CostData> GetData(bool check)
        {
            if (check)
            {
                if (!File.Exists(path))
                {
                    CreateNew();
                }
                Upgrade();
            }
            #region remove code
            //StreamReader reader = new StreamReader(path);
            //reader.ReadLine();
            //reader.ReadLine();
            //List<CostData> costDetails = new List<CostData>();
            //string line;
            //int index = 0;

            //while (!reader.EndOfStream)
            //{
            //    line = reader.ReadLine();
            //    if (line == "") continue;
            //    //CostData costDetail = new CostData(line.Split(',')); // remove code
            //   CostData costDetail = new CostData(line.Split(','), true, index); //modified code for compatibility of files.
            //    costDetails.Add(costDetail);
            //    index++;
            //    if (costDetail.objectCount > 1)
            //    {
            //        while (!reader.EndOfStream)
            //        {
            //            line = reader.ReadLine();
            //            if (line != "")
            //            {
            //                string[] costHeader = line.Split(',');
            //                if (costHeader[0] != "")
            //                {
            //                    string[] type = costHeader[0].Split('.');
            //                    if (type.Count() == 2 && type[type.Count() - 1] != "3wl")
            //                    {
            //                     costDetail.AddObject(line.Split(','));
            //                        index++;
            //                    }
            //                    if (type[type.Count() - 1] != "3mf" && costDetail.name != costHeader[0])
            //                    {
            //                        if (Convert.ToInt32(costHeader[3]) != 1)
            //                            continue;
            //                        else
            //                        {
            //                            costDetail = new CostData(line.Split(','), true, index); //reset the costdetail item & reset to create the next costdetail.
            //                            costDetails.Add(costDetail);
            //                        }
            //                    }
            //                }
            //            }
            //            else
            //            {
            //                break;
            //            }
            //        }
            //    }

            //}

            //reader.Close();
            #endregion

            Dictionary <string, string> costitems = new Dictionary <string, string>();
            CostData        costDetail            = new CostData();
            List <CostData> costDetails           = new List <CostData>();
            List <Dictionary <string, string> > record_history = CostingHistoryCSV.BackUp_Records(CostingHistoryCSV.path);
            bool HasMultipleObject = false;
            for (int i = 0; i < record_history.Count; i++)
            {
                costitems = record_history[i];
                if (costitems["Name"].Substring(costitems["Name"].Length - 4) == ".3wl" || HasMultipleObject)
                {
                    costDetail               = new CostData();
                    costDetail.costObjects   = new List <CostObjectData>();
                    costDetail.name          = costitems["Name"] != "" || costitems["Name"] != "-" ? costitems["Name"] : "";
                    costDetail.objects       = costitems["Objects"] != "" || costitems["Objects"] != "-" ? costitems["Objects"] : "";
                    costDetail.objectCount   = Convert.ToInt32(costDetail.objects);
                    costDetail.weight        = costitems["Weight"] != "" || costitems["Weight"] != "-" ? costitems["Weight"] : "";
                    costDetail.newPrice      = costitems["New"] != "" || costitems["New"] != "-" ? costitems["New"] : "";
                    costDetail.recycledPrice = costitems["Recycled"] != "" || costitems["Recycled"] != "-" ? costitems["Recycled"] : "";
                    costDetail.rate          = costitems["Rate"] != "" || costitems["Rate"] != "-" ? costitems["Rate"] : "";
                    costDetail.time          = costitems["Time"] != "" || costitems["Time"] != "-" ? costitems["Time"] : "";
                    costDetail.created       = costitems["Created"] != "" || costitems["Created"] != "-" ? costitems["Created"] : "";
                    costDetail.cost          = costitems["Cost"] != "" || costitems["Cost"] != "-" ? costitems["Cost"] : "";
                    costDetail.profilename   = costitems.ContainsKey("Profile Settings") ? costitems["Profile Settings"] != "" || costitems["Profile Settings"] != "---" ? costitems["Profile Settings"] : "" : "---";
                    costDetail.machinename   = costitems.ContainsKey("Printer Name") ? costitems["Printer Name"] != "" || costitems["Printer Name"] != "---" ? costitems["Printer Name"] : "" :
                                               costitems.ContainsKey("Machine Name") ? costitems["Machine Name"] : "---";
                    costDetails.Add(costDetail);
                }
                else if (costitems["Name"].Substring(costitems["Name"].Length - 4) == ".3mf" || costitems["Name"].Substring(costitems["Name"].Length - 4) == ".stl")
                {
                    string name, weight, cost, volume;
                    name   = costitems["Name"] != "" || costitems["Name"] != "-" ? costitems["Name"] : "";
                    weight = costitems["Weight"] != "" || costitems["Weight"] != "-" ? costitems["Weight"] : "";
                    cost   = costitems["Cost"] != "" || costitems["Cost"] != "-" ? costitems["Cost"] : "";
                    costDetail.AddObject(name, Convert.ToDouble(weight), Convert.ToDouble(cost));
                }
            }

            return(costDetails);
        }