public void CreateGeneralLedger() { string genName = txtNameGeneral.Text; string genDes = txtDescribeGeneral.Text; if (genName == string.Empty || genDes == string.Empty) { Message.ShowMessage("Check field"); } else if (genName.Length > 50 || genDes.Length > 75) { Message.ShowMessage("Unexpected Length!"); } else { int mainCode = Convert.ToInt32(cboMainHead1.SelectedValue); int maxGenCode; List <GeneralHeads> listGen = MainWindow.listGeneral.Where(x => x.MainCode == mainCode).ToList(); if (listGen.Count != 0) { List <GeneralHeads> lst = listGen.Where(x => x.GeneralName == genName && x.MainCode == mainCode).ToList(); if (lst.Count != 0) { Message.ShowMessage("It exists!"); return; } else { maxGenCode = listGen.Max(x => x.GeneralCode); if (maxGenCode == mainCode * 100 + 99) { Message.ShowMessage("99 General Ledgers are there!"); return; } else { maxGenCode++; } } } else { maxGenCode = mainCode * 100 + 1; } string Query = "INSERT INTO GHeads VALUES(@GCODE, @MCODE, @GHOA, @DESCRIPTION)"; SqlParameter[] para = { new SqlParameter("@GCODE", maxGenCode), new SqlParameter("@MCODE", mainCode), new SqlParameter("@GHOA", genName), new SqlParameter("@DESCRIPTION", genDes) }; try { ListClass lc = new ListClass(); MainWindow.listGeneral = SqlClass.ExecuteNonQuery(Query, MainWindow.listGeneral, lc.GeneralList, para); Message.ShowMessage("General ledger has been added to List"); int cbo1Index = cboMainHead1.SelectedIndex; PopulateComboBox(); cboMainHead1.SelectedIndex = cboMainHead2.SelectedIndex = cbo1Index; cbo1Index = cboGeneralHead.Items.Count - 1; cboGeneralHead.SelectedIndex = cbo1Index; txtNameGeneral.Text = txtDescribeGeneral.Text = string.Empty; } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } }
public void CreateControlLedger() { var a = cboGeneralHead.SelectedItem; string controlName = txtNameControl.Text; string controlDes = txtDescribeControl.Text; if (a == null) { Message.ShowMessage("Create General Ledger"); } else if (controlName == string.Empty || controlDes == string.Empty) { Message.ShowMessage("Check field"); } else if (controlName.Length > 50 || controlDes.Length > 75) { Message.ShowMessage("Length of text is not supported"); } else { int generalCode = Convert.ToInt32(cboGeneralHead.SelectedValue); int mainCode, maxControlCode; mainCode = maxControlCode = 0; List <ControlHeads> lst = MainWindow.listControl.Where(x => x.ControlName == controlName && x.GeneralCode == generalCode).ToList(); if (lst.Count != 0) { Message.ShowMessage("It exists"); return; } else { List <ControlHeads> listControlheads = MainWindow.listControl.Where(x => x.GeneralCode == generalCode).ToList(); mainCode = Convert.ToInt32(cboMainHead2.SelectedValue); if (listControlheads.Count == 0) { maxControlCode = generalCode * 100 + 1; } else { maxControlCode = listControlheads.Max(x => x.ControlCode); if (maxControlCode == generalCode * 100 + 99) { Message.ShowMessage("99 Ledgers already added"); return; } else { maxControlCode++; } } } string Query = "INSERT INTO CHeads VALUES(@CCODE, @GCODE, @MCODE, @CHOA, @DESCRIPTION)"; SqlParameter[] para = { new SqlParameter("@CCODE", maxControlCode), new SqlParameter("@GCODE", generalCode), new SqlParameter("@MCODE", mainCode), new SqlParameter("@CHOA", controlName), new SqlParameter("@DESCRIPTION", controlDes) }; try { ListClass lc = new ListClass(); MainWindow.listControl = SqlClass.ExecuteNonQuery(Query, MainWindow.listControl, lc.ControlList, para); Message.ShowMessage("Control ledger has been added to List"); txtNameControl.Text = txtDescribeControl.Text = string.Empty; } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } }
public void CreateGeneralProduct() { string genProdName = txtNameItem.Text; string genProdDes = txtDescribeItem.Text; var Code = cboMainCategory2.SelectedValue; if (Code == null) { Message.ShowMessage("Create Main Sector First!"); } else if (cboSubCategory.SelectedValue == null) { Message.ShowMessage("Create a Category First!"); } else if (genProdName == string.Empty) { Message.ShowMessage("Check field!"); } else if (genProdName.Length > 25) { Message.ShowMessage("More than 25 Ccharacter is not supported!"); } else if (genProdDes.Length > 50) { Message.ShowMessage("More than 50 Ccharacter is not supported!"); } else { List <GeneralProduct> genList = MainWindow.generalProducts.Where(x => x.GeneralName == genProdName && x.MainId == Convert.ToInt32(cboSubCategory.SelectedValue)).ToList(); if (genList.Count != 0) { Message.ShowMessage("Item exists!"); return; } else { int invCode, mainCode, generalCode, maxGeneralCode; generalCode = maxGeneralCode = 0; invCode = Convert.ToInt32(Code); mainCode = Convert.ToInt32(cboSubCategory.SelectedValue); List <GeneralProduct> geneList = MainWindow.generalProducts.Where(x => x.MainId == mainCode).ToList(); if (geneList.Count != 0) { maxGeneralCode = geneList.Max(x => x.GeneralId); if (maxGeneralCode == mainCode * 100 + 99) { Message.ShowMessage("99 Products have alreadey been added!"); return; } else { generalCode = maxGeneralCode + 1; } } else { generalCode = mainCode * 100 + 1; } double conversionFact; SqlParameter conFact; if (txtConvertItem.Text != string.Empty) { double.TryParse(txtConvertItem.Text, out conversionFact); if (conversionFact == 0) { Message.ShowMessage("Unexpected Factor!"); return; } else if (conversionFact < 0) { Message.ShowMessage("Negative Factor!"); return; } else { conFact = new SqlParameter("@ConToLoose", conversionFact); } } else { conFact = new SqlParameter("@ConToLoose", DBNull.Value); } string Query = "INSERT INTO GProducts VALUES(@GId, @MId, @InvCCode, @GName, @ConToLoose, @Description)"; SqlParameter[] para = { new SqlParameter("@GId", generalCode), new SqlParameter("@MId", mainCode), new SqlParameter("@InvCCode", invCode), new SqlParameter("@GName", txtNameItem.Text), conFact, new SqlParameter("@Description", txtDescribeItem.Text) }; try { ListClass lc = new ListClass(); MainWindow.generalProducts = SqlClass.ExecuteNonQuery(Query, MainWindow.generalProducts, lc.GeneralProductList, para); Message.ShowMessage("Item has been added to List"); txtNameItem.Text = txtDescribeItem.Text = txtConvertItem.Text = string.Empty; } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } } }
public void CreateMainProduct() { string mainProName = txtNameSubCategory.Text; string manProDes = txtDescribeSubCategory.Text; var selectedItem = cboMainCategory1.SelectedValue; if (selectedItem == null) { Message.ShowMessage("Create Main Sector First!"); } else if (mainProName == string.Empty) { Message.ShowMessage("Check field!"); } else if (mainProName.Length > 25) { Message.ShowMessage("More than 25 Character is not supported"); } else if (manProDes.Length > 50) { Message.ShowMessage("More than 50 Character is not supported"); } else { int invCode = Convert.ToInt32(selectedItem); List <MainProduct> productName = MainWindow.mainProducts.Where(x => x.MainName == txtNameSubCategory.Text && x.InventoryCode == invCode).ToList(); if (productName.Count != 0) { Message.ShowMessage("It exists!"); } else { int mainProductCode, maxProductCode; mainProductCode = maxProductCode = 0; List <MainProduct> prod = MainWindow.mainProducts.Where(x => x.InventoryCode == invCode).ToList(); if (prod.Count != 0) { maxProductCode = prod.Max(x => x.MainId); if (maxProductCode != invCode * 100 + 99) { mainProductCode = maxProductCode + 1; } else { Message.ShowMessage("99 Products have alreadey been added!"); return; } } else { mainProductCode = invCode * 100 + 1; } string Query = "INSERT INTO MProducts VALUES(@MId, @InvCCode, @MName, @Description)"; SqlParameter[] para = { new SqlParameter("@MId", mainProductCode), new SqlParameter("@InvCCode", invCode), new SqlParameter("@MName", mainProName), new SqlParameter("@Description", manProDes) }; try { ListClass lc = new ListClass(); MainWindow.mainProducts = SqlClass.ExecuteNonQuery(Query, MainWindow.mainProducts, lc.MainProductList, para); Message.ShowMessage("Product has been added to List"); int cbo1Index = cboMainCategory1.SelectedIndex; PopulateComboBox(); cboMainCategory1.SelectedIndex = cboMainCategory2.SelectedIndex = cbo1Index; int cbo2Index = cboSubCategory.Items.Count - 1; cboSubCategory.SelectedIndex = cbo2Index; txtNameSubCategory.Text = txtDescribeSubCategory.Text = string.Empty; } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } } }
private void CreateCategory() { if (cboControl1.SelectedItem == null) { Message.ShowMessage("Create Control Ledger"); return; } bool notDepreciable = (bool)chkDepreciation.IsChecked; double depreciationRate = 0; string depreciation, categoryName, categoryDescription; categoryName = txtNameCategory.Text; categoryDescription = txtDescribeCategory.Text; depreciation = txtDepreciation.Text; if (categoryName == string.Empty || categoryDescription == string.Empty) { Message.ShowMessage("Check Text fields"); return; } else if (categoryName.Length > 100 || categoryDescription.Length > 150) { Message.ShowMessage("Check Text fields length"); return; } if (!notDepreciable) { if (depreciation == string.Empty) { Message.ShowMessage("Check Depreciation"); return; } else { double.TryParse(depreciation, out depreciationRate); if (depreciationRate <= 0) { Message.ShowMessage("Check Depreciation rate"); return; } } } int CCode, maxItemCode, uppreLimit, itemCode; CCode = Convert.ToInt32(cboControl1.SelectedValue); List <FixedAssets> FAlist = MainWindow.listFixedAssets.Where(x => x.CCode == CCode).ToList(); maxItemCode = FAlist.Count == 0 ? 0 : FAlist.Max(x => x.ItemCode); uppreLimit = CCode * 1000 + 999; if (maxItemCode == uppreLimit) { Message.ShowMessage("999 Items added under control account"); return; } else { itemCode = maxItemCode == 0 ? CCode * 1000 + 1 : maxItemCode + 1; } string Query = "INSERT INTO FixedAssetsItem VALUES(@CCode, @ItemCode, @Depreciation, @ItemName, @DESCRIPTION)"; string CS = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlParameter Depre = depreciationRate == 0 ? new SqlParameter("@Depreciation", DBNull.Value) : new SqlParameter("@Depreciation", depreciationRate); SqlParameter[] para = { new SqlParameter("@CCode", CCode), new SqlParameter("@ItemCode", itemCode), Depre, new SqlParameter("@ItemName", categoryName), new SqlParameter("@DESCRIPTION", categoryDescription) }; ListClass lc = new ListClass(); try { con.Open(); MainWindow.listFixedAssets = SqlClass.ExecuteNonQuery(Query, MainWindow.listFixedAssets, lc.FixedAssetsControlList, para); Message.ShowMessage("Item added to List"); } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } }
private void CreateFAControlAccount() { string controlName, controlDescription; controlName = txtNameControl.Text; controlDescription = txtDescribeControl.Text; if (controlName == string.Empty || controlDescription == string.Empty) { Message.ShowMessage("Fill in the Text Boxes"); return; } if (controlName.Length > 100 || controlDescription.Length > 150) { Message.ShowMessage("Unexpected Length"); return; } List <GeneralHeads> FAGen = MainWindow.listGeneral.Where(x => x.GeneralName == "Fixed Assets").ToList(); int FAGenCode = FAGen.Select(x => x.GeneralCode).FirstOrDefault(); List <ControlHeads> FAControl = MainWindow.listControl.Where(x => x.GeneralCode == FAGenCode).ToList(); List <ControlHeads> names = FAControl.Where(x => x.ControlName == controlName).ToList(); if (names.Count != 0) { Message.ShowMessage("Head Exists"); return; } int controlCode = 0; int maxControlCode = FAControl.Select(x => x.ControlCode).LastOrDefault(); int upperLimit = FAGenCode * 100 + 99; if (maxControlCode != upperLimit) { controlCode = maxControlCode == 0 ? FAGenCode * 100 + 1 : maxControlCode + 1; } else { Message.ShowMessage("99 Items added"); return; } int FAMainCode = FAGen.Select(x => x.MainCode).FirstOrDefault(); string Query = "INSERT INTO CHeads VALUES(@CCODE, @GCODE, @MCODE, @CHOA, @DESCRIPTION)"; string CS = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlParameter[] para = { new SqlParameter("@CCODE", controlCode), new SqlParameter("@GCODE", FAGenCode), new SqlParameter("@MCODE", FAMainCode), new SqlParameter("@CHOA", controlName), new SqlParameter("@DESCRIPTION", controlDescription) }; ListClass lc = new ListClass(); try { con.Open(); MainWindow.listControl = SqlClass.ExecuteNonQuery(Query, MainWindow.listControl, lc.ControlList, para); Message.ShowMessage("Ledger Created"); PopulateComboBox(); cboControl1.SelectedIndex = MainWindow.listControl.FindIndex(x => x.ControlCode == controlCode); } catch (Exception ex) { Message.ShowMessage(ex.ToString()); } } }