private void AddExpenseButton_Click(object sender, RoutedEventArgs e) { Expense expense = new Expense(); decimal amount; if (!decimal.TryParse(AmountBox.Text, out amount)) { MessageBox.Show("Please enter amount correctly...", "Error"); return; } if (ExpenseTypeComboBox.Text == "") { MessageBox.Show("Please enter an expense type..."); return; } int id = Convert.ToInt32(db.ExecuteQuery <decimal>("SELECT IDENT_CURRENT('Expense') +1;").FirstOrDefault()); expense.Id = id; expense.Amount = amount; expense.Remarks = RemarkTextBox.Text; expense.Date = SelectedDate.SelectedDate ?? DateTime.Today; expense.ExpenseType = ExpenseTypeComboBox.Text; db.Expenses.InsertOnSubmit(expense); db.SubmitChanges(); MessageBox.Show("Data Added...", "Information"); TitleTextBox.Text = " Manage Expense"; refreshData(); }
private void ImportRulesButton_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("You have selected " + CostingRuleGrid.SelectedItems.Count + " Costing Rules and " + ServiceRuleGrid.SelectedItems.Count + " Service Rules. Are you sure you want to import them? ", "Confirm", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { List <CostingRule> costingRules = CostingRuleGrid.SelectedItems.Cast <CostingRule>().ToList(); List <ServiceRule> serviceRules = ServiceRuleGrid.SelectedItems.Cast <ServiceRule>().ToList(); BillingDataDataContext db = new BillingDataDataContext(); Quotation quotation = db.Quotations.Single(x => x.CLCODE == clientO.CLCODE); foreach (CostingRule CRule in costingRules) { int id; id = Convert.ToInt32(db.ExecuteQuery <decimal>("SELECT IDENT_CURRENT('Rule') +1;").FirstOrDefault()); CRule.Id = id; JavaScriptSerializer js = new JavaScriptSerializer(); string serialized = js.Serialize(CRule); Rule r = new Rule(); r.Type = 1; r.Properties = serialized; r.QID = quotation.Id; r.Remark = "Imported rule from " + client.CLNAME; db.Rules.InsertOnSubmit(r); db.SubmitChanges(); } foreach (ServiceRule SRule in serviceRules) { int id; id = Convert.ToInt32(db.ExecuteQuery <decimal>("SELECT IDENT_CURRENT('Rule') +1;").FirstOrDefault()); SRule.Id = id; JavaScriptSerializer js = new JavaScriptSerializer(); string serialized = js.Serialize(SRule); Rule r = new Rule(); r.Type = 2; r.Properties = serialized; r.QID = quotation.Id; r.Remark = "Imported rule from " + client.CLNAME; db.Rules.InsertOnSubmit(r); db.SubmitChanges(); } MessageBox.Show("Rules imported."); this.Close(); } }
private void AddRuleButton_Click(object sender, RoutedEventArgs e) { Rule r; BillingDataDataContext db = new BillingDataDataContext(); if (!isUpdate) { r = new Rule(); } else { if (rule != null) { r = rule; } else { MessageBox.Show("Some Error Occured"); r = new Rule(); this.Close(); } } double startW = 0, endW = 0; string errorMsg = ""; double temp; if (double.TryParse(FromWeightBox.Text, out temp)) { startW = temp; } else { errorMsg = errorMsg + "Enter From Weight Properly \n"; } if (double.TryParse(ToWeightBox.Text, out temp)) { endW = temp; } else { errorMsg = errorMsg + "Enter To Weight Properly \n"; } if (startW > endW) { errorMsg += "Starting weight cannot be greater than ending weight. \n"; } char type = 'U'; if (RangeTypeRadio.IsChecked == true) { type = 'R'; } if (StepTypeRadio.IsChecked == true) { type = 'S'; } if (MultiplierTypeRadio.IsChecked == true) { type = 'M'; } double doxAmount = 0, ndoxAmount = 0; if (!double.TryParse(DOXAmountBox.Text, out doxAmount)) { errorMsg += "Enter dox amount properly \n"; } if (!double.TryParse(NDoxAmountBox.Text, out ndoxAmount)) { errorMsg += "Enter non dox amount properly \n"; } double doxStartValue = 0, ndoxStartValue = 0; double stepweight = 0; if (!double.TryParse(StepBlockBox.Text, out stepweight) && StepTypeRadio.IsChecked == true) { errorMsg += "Enter Step Weight Properly \n"; } if (errorMsg != "") { MessageBox.Show("Please correct following errors: " + errorMsg); return; } List <string> selectedServiceList = ((ServiceTwinBox.SelectedListSource) ?? new List <Service>()).Cast <Service>().Select(x => x.SER_CODE).ToList(); List <string> selectedZoneList = ((ZoneTwinBox.SelectedListSource) ?? new List <ZONE>()).Cast <ZONE>().Select(x => x.zcode).ToList(); List <String> selectedCityList = ((CitiesTwinBox.SelectedListSource) ?? new List <City>()).Cast <City>().Select(x => x.CITY_CODE).ToList(); List <string> selectedStateList = ((StateTwinBox.SelectedListSource) ?? new List <State>()).Cast <State>().Select(x => x.STATE_CODE).ToList(); List <string> selectedServiceGroupList = ((ServiceGroupTwinBox.SelectedListSource) ?? new List <ServiceGroup>()).Cast <ServiceGroup>().Select(x => x.GroupName).ToList(); RuleCR.ServiceList = selectedServiceList; RuleCR.ZoneList = selectedZoneList; RuleCR.CityList = selectedCityList; RuleCR.StateList = selectedStateList; RuleCR.ServiceGroupList = selectedServiceGroupList; RuleCR.startW = startW; int id; id = Convert.ToInt32(db.ExecuteQuery <decimal>("SELECT IDENT_CURRENT('Rule') +1;").FirstOrDefault()); if (!isUpdate) { RuleCR.Id = id; r.QID = quoation.Id; } RuleCR.endW = endW; RuleCR.type = type; RuleCR.doxAmount = doxAmount; RuleCR.ndoxAmount = ndoxAmount; RuleCR.stepWeight = stepweight; RuleCR.dStartValue = doxStartValue; RuleCR.ndStartValue = ndoxStartValue; JavaScriptSerializer js = new JavaScriptSerializer(); string serialized = js.Serialize(RuleCR); r.Type = 1; r.Properties = serialized; r.Remark = this.RemarkBox.Text ?? " "; if (!isUpdate) { db.Rules.InsertOnSubmit(r); } else { Rule ruledb = db.Rules.Where(x => x.ID == r.ID).FirstOrDefault(); if (ruledb == null) { MessageBox.Show("Some Error Occured"); return; } else { setvalue(ruledb, r); } } bool isdone = false; if (validate()) { try { db.SubmitChanges(); isdone = true; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } if (!isUpdate) { if (isdone) { if (MessageBox.Show("Do you want to add a new rule for this configuration of service and destination", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { FromWeightBox.Text = (RuleCR.endW + 0.0001).ToString(); ToWeightBox.Text = ""; currentGrid = 6; currentGridObj.Visibility = Visibility.Collapsed; currentGridObj = Step6Grid; currentGridObj.Visibility = Visibility.Visible; StepBlock.Text = "Step " + currentGrid.ToString() + " of 7"; } else { this.Close(); } } } else { if (isdone) { MessageBox.Show("Rule updated successfully", "Information"); this.Close(); } } } }
public PrintMainWindow(Invoice inv) { try { InitializeComponent(); BillingDataDataContext db = new BillingDataDataContext(); List <RuntimeData> data = UtilityClass.convertTransListToRuntimeList(db.ExecuteQuery <Transaction>(@" SELECT [ID] ,[AmountPayed] ,[AmountCharged] ,[ConnsignmentNo] ,[Weight] ,[WeightByFranchize] ,[Destination] ,[DestinationPin] ,[UserId] ,[BookingDate] ,[AddDate] ,[LastModified] ,[Type] ,[Mode] ,[DOX] ,[ServiceTax] ,[SplDisc] ,[InvoiceNo] ,[InvoiceDate] ,[CustCode] ,[TransMF_No] ,[BilledWeight] FROM [BillingDatabase].[dbo].[InvoiceView] where [BillId] = '" + inv.BillId + @"' ").ToList()); source = UtilityClass.convertToRuntimeVIew(data.OrderBy(x => x.BookingDate).ThenBy(z => z.ConsignmentNo).ToList()); rs = new ReportDataSource(); rs.Value = source; if (inv.Misc == null) { inv.Misc = 0; } if (inv.PreviousDue == null) { inv.PreviousDue = 0; } Client clc = DataSources.ClientCopy.SingleOrDefault(x => x.CLCODE == inv.ClientCode); List <ReportParameter> repParams = new List <ReportParameter>(); DateTime FromDate = data.Min(x => x.BookingDate); DateTime ToDate = data.Max(x => x.BookingDate); string dateString = FromDate.ToString("dd/MM/yyyy") + " to " + ToDate.ToString("dd/MM/yyyy"); repParams.Add(new ReportParameter("DateString", dateString)); string descriptionString = "Total Consignments: " + source.Count; repParams.Add(new ReportParameter("DescriptionString", descriptionString)); repParams.Add(new ReportParameter("MainAmountString", String.Format("{0:0.00}", inv.Basic))); repParams.Add(new ReportParameter("DiscountPString", String.Format("{0:0.00}", inv.Discount))); repParams.Add(new ReportParameter("FuelString", String.Format("{0:0.00}", inv.Fuel))); repParams.Add(new ReportParameter("FuelAmount", String.Format("{0:0.00}", inv.fuelAmount))); repParams.Add(new ReportParameter("ServiceTaxString", String.Format("{0:0.00}", inv.STax))); repParams.Add(new ReportParameter("ServiceTaxAmount", String.Format("{0:0.00}", inv.taxAmount))); repParams.Add(new ReportParameter("DiscountAmountString", String.Format("{0:0.00}", inv.discountAmount))); repParams.Add(new ReportParameter("SWC", String.Format("{0:0.00}", inv.SWC))); repParams.Add(new ReportParameter("MiscellaneousAmountString", String.Format("{0:0.00}", inv.Misc))); repParams.Add(new ReportParameter("TNC", Configs.Default.TNC)); repParams.Add(new ReportParameter("TotalAmountString", String.Format("{0:0.00}", inv.totalAmount))); repParams.Add(new ReportParameter("TotalAmountInWordString", UtilityClass.NumbersToWords((int)Math.Round(inv.totalAmount)))); if (inv.PreviousDue == 0 || inv.PreviousDue == null) { repParams.Add(new ReportParameter("PreviousDueString", "")); } else { repParams.Add(new ReportParameter("PreviousDueString", String.Format("{0:0.00}", inv.PreviousDue))); repParams.Add(new ReportParameter("PreviousDueCheck", "Previous Due .:")); } repParams.Add(new ReportParameter("CompanyName", Configs.Default.CompanyName)); repParams.Add(new ReportParameter("ComapnyPhoneNo", Configs.Default.CompanyPhone)); repParams.Add(new ReportParameter("CompanyAddress", Configs.Default.CompanyAddress)); repParams.Add(new ReportParameter("CompanyEmail", Configs.Default.CompanyEmail)); repParams.Add(new ReportParameter("CompanyFax", Configs.Default.CompanyFax)); repParams.Add(new ReportParameter("TinNumber", Configs.Default.Tin ?? "")); repParams.Add(new ReportParameter("ClientName", clc.CLNAME)); repParams.Add(new ReportParameter("ClientAddress", clc.ADDRESS)); repParams.Add(new ReportParameter("ClientPhoneNo", clc.CONTACTNO)); repParams.Add(new ReportParameter("ServiceTaxNumber", Configs.Default.ServiceTaxno ?? "")); // repParams.Add(new ReportParameter("Tinnumber", Configs.Default.Tin)); DateTime invDateTime; if (inv.BillId.Length < 14) { invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmm", CultureInfo.InvariantCulture); } else { invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmmss", CultureInfo.InvariantCulture); } repParams.Add(new ReportParameter("InvoiceDate", invDateTime.ToString("dd-MMM-yyyy"))); repParams.Add(new ReportParameter("InvoiceNumber", inv.BillId)); BillViewer.LocalReport.ReportPath = "Report1.rdlc"; BillViewer.LocalReport.DataSources.Clear(); rs.Name = "DataSet1"; BillViewer.LocalReport.DataSources.Add(rs); BillViewer.LocalReport.SetParameters(repParams); BillViewer.LocalReport.DisplayName = inv.ClientName + "-" + inv.BillId; BillViewer.RefreshReport(); } catch (Exception) { MessageBox.Show("Error opening file."); this.Close(); } }
private void AddRuleButton_Click(object sender, RoutedEventArgs e) { Rule r; BillingDataDataContext db = new BillingDataDataContext(); double startW = 0, endW = 0; string errorMsg = ""; double temp; if (double.TryParse(FromWeightBox.Text, out temp)) { startW = temp; } else { errorMsg = errorMsg + "Enter From Weight Properly \n"; } if (double.TryParse(ToWeightBox.Text, out temp)) { endW = temp; } else { errorMsg = errorMsg + "Enter To Weight Properly \n"; } if (startW > endW) { errorMsg += "Starting weight cannot be greater than ending weight. \n"; } double stepweight = 0; if (!double.TryParse(StepBox.Text, out stepweight) && StepRadio.IsChecked == true) { errorMsg += "Enter Step Weight Properly \n"; } char type; double step = 0; if (WholeRadio.IsChecked == true) { type = 'W'; } else { type = 'S'; if (!double.TryParse(StepBox.Text, out step) && StepRadio.IsChecked == true) { errorMsg += "Enter Step Weight Properly \n"; } } char change; if (IncRadio.IsChecked == true) { change = 'I'; } else { change = 'D'; } char mode; float per = 0; if (PerRadio.IsChecked == true) { mode = 'P'; if (!float.TryParse(ValueBox.Text, out per)) { errorMsg += "Enter Percentage Properly\n"; } } else { mode = 'A'; if (!float.TryParse(AmountBox.Text, out per)) { errorMsg += "Enter Percentage Properly\n"; } } char applicable; applicable = 'O'; if (errorMsg != "") { MessageBox.Show("Please correct following errors: " + errorMsg); return; } List <string> selectedServiceList = ((ServiceTwinBox.SelectedListSource) ?? new List <Service>()).Cast <Service>().Select(x => x.SER_CODE).ToList(); List <string> selectedZoneList = ((ZoneTwinBox.SelectedListSource) ?? new List <ZONE>()).Cast <ZONE>().Select(x => x.zcode).ToList(); List <String> selectedCityList = ((CitiesTwinBox.SelectedListSource) ?? new List <City>()).Cast <City>().Select(x => x.CITY_CODE).ToList(); List <string> selectedStateList = ((StateTwinBox.SelectedListSource) ?? new List <State>()).Cast <State>().Select(x => x.STATE_CODE).ToList(); List <string> selectedServiceGroupList = ((ServiceGroupTwinBox.SelectedListSource) ?? new List <ServiceGroup>()).Cast <ServiceGroup>().Select(x => x.GroupName).ToList(); if (RuleSR == null || rule == null) { r = new Rule(); RuleSR = new ServiceRule(); int id; id = Convert.ToInt32(db.ExecuteQuery <decimal>("SELECT IDENT_CURRENT('Rule') +1;").FirstOrDefault()); RuleSR.Id = id; } else { r = db.Rules.SingleOrDefault(x => x.ID == rule.ID); } RuleSR.ServiceList = selectedServiceList; RuleSR.ZoneList = selectedZoneList; RuleSR.CityList = selectedCityList; RuleSR.StateList = selectedStateList; RuleSR.ServiceGroupList = selectedServiceGroupList; RuleSR.startW = startW; RuleSR.endW = endW; RuleSR.type = type; RuleSR.change = change; RuleSR.mode = mode; RuleSR.per = per; RuleSR.step = step; RuleSR.stepweight = stepweight; RuleSR.applicable = applicable; JavaScriptSerializer js = new JavaScriptSerializer(); string serialized = js.Serialize(RuleSR); r.Type = 2; r.Properties = serialized; if (!isUpdate) { r.QID = quotation.Id; } r.Remark = this.RemarkBox.Text; if (!isUpdate) { db.Rules.InsertOnSubmit(r); } if (validate()) { try { db.SubmitChanges(); isdone = true; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } if (isdone) { if (!isUpdate) { MessageBox.Show("New Service Rule Added"); } else { MessageBox.Show("Service Rule updated"); } this.Close(); } } }