Esempio n. 1
0
 private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         RuntimeData rData = ((RuntimeData)e.Row.Item);
         double      weight;
         if (double.TryParse((e.EditingElement as TextBox).Text, out weight))
         {
             if (e.Column.Header.ToString() == "Billed Weight")
             {
                 rData.BilledWeight = weight;
             }
             else if (e.Column.Header.ToString() == "Billed Amount")
             {
                 rData.FrAmount = (decimal)weight;
             }
         }
         else
         {
             MessageBox.Show("Unable to edit record!! Please check if input does not contain any invalid characters.", "Error");
             return;
         }
         if (rData == null)
         {
             MessageBox.Show("Unable to edit record....");
             return;
         }
         RuntimeData sData = dataGridHelper.getCurrentDataStack.SingleOrDefault(x => x.ConsignmentNo == rData.ConsignmentNo);
         if (sData == null)
         {
             MessageBox.Show("Unable to edit transaction. Please reload the data and try again..", "Error");
             return;
         }
         BillingDataDataContext db    = new BillingDataDataContext();
         RuntimeData            dData = db.RuntimeDatas.SingleOrDefault(x => x.ConsignmentNo == rData.ConsignmentNo && x.UserId == SecurityModule.currentUserName && dataGridHelper.currentSheetNumber == x.SheetNo);
         if (dData == null)
         {
             MessageBox.Show("Unable to edit transaction. Please check if data exists and try again..", "Error");
             return;
         }
         if (e.Column.Header.ToString() == "Billed Weight")
         {
             dData.BilledWeight = rData.BilledWeight;
             dData.FrAmount     = (decimal)UtilityClass.getCost(rData.CustCode, weight, rData.Destination, rData.Type.Trim(), rData.DOX ?? 'N');
             db.SubmitChanges();
             rData.FrAmount     = dData.FrAmount;
             sData.BilledWeight = dData.BilledWeight;
             sData.FrAmount     = dData.FrAmount;
         }
         if (e.Column.Header.ToString() == "Billed Amount")
         {
             dData.FrAmount = rData.FrAmount;
             db.SubmitChanges();
             sData.FrAmount = rData.FrAmount;
         }
     }
 }
        private void AddstockLabel_Click(object sender, RoutedEventArgs e)
        {
            bool flag = false;

            if (getdetails())
            {
                BillingDataDataContext db = new BillingDataDataContext();
                if (!isUpdate)
                {
                    db.Stocks.InsertOnSubmit(this.s);
                    try
                    {
                        try
                        {
                            db.SubmitChanges();
                            flag = true;
                        }
                        catch (Exception ex) { MessageBox.Show(ex.Message); flag = false; return; }
                    }
                    catch (Exception d) { flag = false; MessageBox.Show(d.Message); return; }
                    if (flag)
                    {
                        MessageBox.Show("Stock added", "Info");
                        this.Close();
                    }
                }
                else
                {
                    Stock stockEntry = db.Stocks.SingleOrDefault(x => x.ID == s.ID);
                    if (stockEntry == null)
                    {
                        MessageBox.Show("This stock entry doesn't exists", "Error");
                        return;
                    }
                    else
                    {
                        stockEntry.BookNo     = s.BookNo;
                        stockEntry.cost       = s.cost;
                        stockEntry.Date       = s.Date;
                        stockEntry.desc       = s.desc;
                        stockEntry.StockEnd   = s.StockEnd;
                        stockEntry.StockStart = s.StockStart;
                        stockEntry.UserId     = s.UserId;
                        try
                        {
                            db.SubmitChanges();
                            MessageBox.Show("Stock successfully updated");
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Cannot update stock entry. Error: " + ex.Message);
                        }
                    }
                }
            }
        }
 private void Save_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         db.SubmitChanges();
         MessageBox.Show("Data saved..", "Information");
         TitleTextBox.Text = " Manage Expense";
     }
     catch (Exception exe)
     {
         MessageBox.Show("Unable to add data... Error: " + exe.Message, "Error");
     }
 }
Esempio n. 4
0
        private void DeleteRule_Click(object sender, RoutedEventArgs e)
        {
            BillingDataDataContext db = new BillingDataDataContext();

            if (CostingRuleGrid.Visibility == Visibility.Visible && CostingRuleGrid.SelectedItems != null)
            {
                if (MessageBox.Show("Do you want delete " + CostingRuleGrid.SelectedItems.Count.ToString() + " Rule", "Confirm", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    List <CostingRule> dcr = CostingRuleGrid.SelectedItems.Cast <CostingRule>().ToList();
                    CostingRuleGrid.SelectedItem = null;
                    List <int>  Ids = dcr.Select(x => x.Id).ToList();
                    List <Rule> dr  = db.Rules.Where(x => Ids.Contains(x.ID)).ToList();
                    db.Rules.DeleteAllOnSubmit(dr);
                }
            }
            if (ServiceRuleGrid.Visibility == Visibility.Visible && ServiceRuleGrid.SelectedItems != null)
            {
                if (MessageBox.Show("Do you want delete " + ServiceRuleGrid.SelectedItems.Count.ToString() + " Rule", "Confirm", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    List <ServiceRule> dcr = ServiceRuleGrid.SelectedItems.Cast <ServiceRule>().ToList();
                    ServiceRuleGrid.SelectedItem = null;
                    List <int>  Ids = dcr.Select(x => x.Id).ToList();
                    List <Rule> dr  = db.Rules.Where(x => Ids.Contains(x.ID)).ToList();
                    db.Rules.DeleteAllOnSubmit(dr);
                }
            }
            db.SubmitChanges();
            LoadClientRules();
            this.CostingRuleGrid.Items.Refresh();
            this.ServiceRuleGrid.Items.Refresh();
        }
Esempio n. 5
0
        private void EditRule_Click(object sender, RoutedEventArgs e)
        {
            BillingDataDataContext db = new BillingDataDataContext();

            if (CostingRuleGrid.Visibility == Visibility.Visible && CostingRuleGrid.SelectedItem != null)
            {
                if (MessageBox.Show("Do you Want edit this Rule", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    CostingRule dcr = (CostingRule)CostingRuleGrid.SelectedItem;
                    AddRule     win = new AddRule(dcr.Id);
                    win.Closed += win_Closed;
                    win.Show();
                    CostingRuleGrid.SelectedItem = null;
                }
            }
            if (ServiceRuleGrid.Visibility == Visibility.Visible && ServiceRuleGrid.SelectedItem != null)
            {
                if (MessageBox.Show("Do you Want edit this Rule", "", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    ServiceRule    dcr = (ServiceRule)ServiceRuleGrid.SelectedItem;
                    AddServiceRule win = new AddServiceRule(dcr.Id);
                    win.Closed += win_Closed;
                    win.Show();
                    ServiceRuleGrid.SelectedItem = null;
                }
            }
            db.SubmitChanges();
        }
        private void DeleteEmployeeGrid_Click(object sender, RoutedEventArgs e)
        {
            BillingDataDataContext db = new BillingDataDataContext();

            if (mangaEmployeegrid.SelectedItem != null)
            {
                if (((Employee)mangaEmployeegrid.SelectedItem).UserName != Configs.Default.SuperUser)
                {
                    var emp = db.Employees.Where(x => x.Id == ((Employee)mangaEmployeegrid.SelectedItem).Id).FirstOrDefault();
                    emp.Status = 'D';
                    try
                    {
                        db.SubmitChanges();
                        reloadgrid(null, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Super User cannot be deleted");
                }
            }
        }
        private void DeleteCityButton_Click(object sender, RoutedEventArgs e)
        {
            if (CityDataGrid.SelectedItems.Count != 1)
            {
                MessageBox.Show("Select 1 city to delete");
                return;
            }
            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this city?", "Confirm", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                if (db == null)
                {
                    db = new BillingDataDataContext();
                }
                City city = db.Cities.SingleOrDefault(x => x.CITY_CODE == ((City)CityDataGrid.SelectedItem).CITY_CODE);
                if (city == null)
                {
                    MessageBox.Show("No such city exists.");
                    return;
                }
                db.Cities.DeleteOnSubmit(city);
                db.SubmitChanges();
            }
            ReloadCityButton_Click(null, null);
        }
Esempio n. 8
0
 private void DeleteClientGridButton_Click(object sender, RoutedEventArgs e)
 {
     if (mangaclientgrid.SelectedItems.Count != 1)
     {
         MessageBox.Show("Please select 1 client to delete", "Error");
         return;
     }
     if (MessageBox.Show("Are you sure you want to delete this client?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         Client client = (Client)mangaclientgrid.SelectedItem;
         client = db.Clients.SingleOrDefault(x => x.CLCODE == client.CLCODE);
         if (client == null)
         {
             MessageBox.Show("This client does not exists.", "Error");
             return;
         }
         if (client.CLCODE == "<NONE>" || client.CLCODE == "<DTDC>")
         {
             MessageBox.Show("This client cannot be deleted");
             return;
         }
         db.Clients.DeleteOnSubmit(client);
         try
         {
             db.SubmitChanges();
             MessageBox.Show("Client deleted.", "Success");
         }
         catch (Exception ex)
         {
             MessageBox.Show("Deletion failed with error : " + ex.Message, "Failure");
         }
         DataSources.refreshClientList();
         ReloadClientGridButton_Click(null, null);
     }
 }
Esempio n. 9
0
 private void updateEmployee()
 {
     if (Password.Password == ConfirmPass.Password && Password.Password != "" && Password.Password != null)
     {
         setEmpFromFields();
         BillingDataDataContext db = new BillingDataDataContext();
         Employee data             = db.Employees.Single(x => x.Id == emp.Id);
         removeduplicatePermission();
         db.User_permissions.InsertAllOnSubmit(returnUserPermissionList((List <Permission>)(viewsourceUserPermission.Source)));
         setDataFromEmp(data);
         try
         {
             db.SubmitChanges();
             isaddinsert = true;
             SecurityModule.Reload();
         }
         catch (Exception ex) { MessageBox.Show(ex.Message); isaddinsert = false; return; }
         this.Close();
     }
     else
     {
         MessageBox.Show("Password Invalid");
     }
     if (isaddinsert)
     {
         MessageBox.Show("Employee Updated");
         this.Close();
     }
 }
Esempio n. 10
0
        public void add()
        {
            string errorMsg = validate();

            if (errorMsg == "")
            {
                client           = new Client();
                client.CLNAME    = ClientName.Text;
                client.Status    = 'A';
                client.ADDRESS   = ClientAddress.Text;
                client.CONTACTNO = ClientPhoneNo.Text;
                client.EMAILID   = CLientEmailAddress.Text;
                client.CLCODE    = ClientCode.Text;
                client.FUEL      = float.Parse(ClientFuel.Text);
                client.INTRODATE = DateTime.Now;
                client.STAX      = float.Parse(ServiceTax.Text);
                client.AMTDISC   = float.Parse(DiscountBox.Text);

                db.Clients.InsertOnSubmit(client);
                try
                {
                    db.SubmitChanges();
                    DataSources.refreshClientList();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); return; }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please correct following errors: " + errorMsg);
            }
        }
Esempio n. 11
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Func <Transaction, bool> whereQuery = (Func <Transaction, bool>)e.Argument;

            worker.ReportProgress(1);
            BillingDataDataContext db = new BillingDataDataContext();

            List <Transaction> transactions = db.Transactions.Where(whereQuery).ToList();
            double             transCount   = transactions.Count;

            double i = 0;

            foreach (Transaction trans in transactions)
            {
                if (trans.ConnsignmentNo == "X10477603")
                {
                    Debug.WriteLine("ABC");
                }
                trans.AmountCharged = (decimal)UtilityClass.getCost(trans.CustCode, trans.BilledWeight ?? 0, trans.Destination, trans.Type.Trim(), trans.DOX);
                if (trans.Insurance != null)
                {
                    trans.AmountCharged = trans.AmountCharged + (decimal)trans.Insurance;
                }

                worker.ReportProgress((int)((i / transCount) * 94 + 1));
                i++;
            }
            ChangeSet changeSet = db.GetChangeSet();

            db.SubmitChanges();
            worker.ReportProgress(100);
            e.Result = "Completed for " + ((int)transCount).ToString() + " transactions";
        }
Esempio n. 12
0
        public void update()
        {
            string errorMsg = validate();

            if (errorMsg == "")
            {
                var db   = new BillingDataDataContext();
                var data = db.Clients.Single(x => x.CLCODE == client.CLCODE);
                data.CLNAME    = ClientName.Text ?? "";
                data.ADDRESS   = ClientAddress.Text ?? "";
                data.EMAILID   = CLientEmailAddress.Text ?? "";
                data.CONTACTNO = ClientPhoneNo.Text ?? "";
                data.FUEL      = double.Parse(ClientFuel.Text ?? "");
                data.STAX      = double.Parse(ServiceTax.Text);
                data.AMTDISC   = double.Parse(DiscountBox.Text);
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); return; }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please correct following errors: " + errorMsg);
            }
        }
Esempio n. 13
0
        private void AddNewEmployee()
        {
            if (Password.Password == ConfirmPass.Password && Password.Password != "" && Password.Password != null)
            {
                setEmpFromFields();

                emp.Status = 'A';
                BillingDataDataContext db = new BillingDataDataContext();
                db.Employees.InsertOnSubmit(emp);
                Debug.WriteLine("Type is" + UserPermisstionToset.ItemsSource.GetType().ToString());
                db.User_permissions.InsertAllOnSubmit(returnUserPermissionList((List <Permission>)(viewsourceUserPermission.Source)));
                try
                {
                    db.SubmitChanges();
                    isaddinsert = true;
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); isaddinsert = false; return; }
                this.Close();
            }
            else
            {
                MessageBox.Show("Password Invalid");
            }
            if (isaddinsert)
            {
                MessageBox.Show("Employee Add");
                this.Close();
            }
        }
 private void DeleteInvoiceButton_Click(object sender, RoutedEventArgs e)
 {
     if (InvoiceDatagrid.SelectedItems.Count != 1)
     {
         MessageBox.Show("Please select 1 invoice to delete", "Message");
         return;
     }
     if (MessageBox.Show("Are you sure you want to delete this invoice?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         BillingDataDataContext db = new BillingDataDataContext();
         Invoice invoice           = db.Invoices.SingleOrDefault(x => x.BillId == ((Invoice)InvoiceDatagrid.SelectedItem).BillId);
         if (invoice == null)
         {
             MessageBox.Show("This invoice doesn't exists or has already been deleted..", "Error");
             return;
         }
         db.Invoices.DeleteOnSubmit(invoice);
         try
         {
             db.SubmitChanges();
             MessageBox.Show("Invoice successfully deleted. Click on fetch button to view the changes.", "Success");
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error in deleting invoice. Error Message: " + ex.Message, "Error");
         }
     }
 }
        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 SaveInvoiceButton_Click(object sender, RoutedEventArgs e)
        {
            if (source == null)
            {
                MessageBox.Show("Please print the invoice first...", "Error");
                return;
            }
            MessageBoxResult result = MessageBox.Show("Do you want to save this invoice? ", "Confirm", MessageBoxButton.YesNo);
            int count = source.Where(x => x.TransactionId == null || x.TransactionId == Guid.Empty).Count();

            if (count > 0)
            {
                MessageBox.Show("Selected transactions set contains records that are not yet saved in the database. This bill cannot be saved.");
                return;
            }
            if (result == MessageBoxResult.Yes)
            {
                BillingDataDataContext db = new BillingDataDataContext();
                if (db.Invoices.Where(x => x.BillId == invoice.BillId).Count() > 0)
                {
                    MessageBox.Show("This invoice is already saved", "Error..");
                    return;
                }
                try
                {
                    db.Invoices.InsertOnSubmit(invoice);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                    return;
                }
                foreach (var item in source)
                {
                    InvoiceAssignment assign = new InvoiceAssignment();
                    assign.BillId          = invoice.BillId;
                    assign.Id              = Guid.NewGuid();
                    assign.TransactionId   = (Guid)item.TransactionId;
                    assign.BilledAmount    = (double)(item.FrAmount ?? 0);
                    assign.BilledWeight    = (double)(item.BilledWeight ?? item.Weight);
                    assign.Destination     = item.Destination;
                    assign.DestinationDesc = item.CITY_DESC;
                    db.InvoiceAssignments.InsertOnSubmit(assign);
                }
                try
                {
                    db.SubmitChanges();
                    MessageBox.Show("Invoice Saved... ", "Information");
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 17
0
        public void insertRuntimeData(List <RuntimeData> data, int sheetNo, bool isLoadedFromFile, DateTime?toDate = null, DateTime?fromDate = null)
        {
            BillingDataDataContext db = new BillingDataDataContext();

            if (isLoadedFromFile == false)
            {
                return;
            }

            foreach (var runData in data)
            {
                runData.UserId  = SecurityModule.currentUserName;
                runData.SheetNo = sheetNo;
                db.RuntimeDatas.InsertOnSubmit(runData);
                db.SubmitChanges();
            }
            db.SubmitChanges();
            data.Clear();
        }
Esempio n. 18
0
        public bool SaveData()
        {
            BillingDataDataContext db   = new BillingDataDataContext();
            RuntimeData            data = null;

            data = fillData(data);
            if (data == null)
            {
                return(false);
            }
            data.SheetNo = sheetNo;
            data.UserId  = SecurityModule.currentUserName;
            if (!SubClientList.ContainsKey(data.CustCode))
            {
                SubClientList.Add(data.CustCode, new List <string>()
                {
                    data.SubClient
                });
            }
            else
            {
                if (!SubClientList[data.CustCode].Contains(data.SubClient))
                {
                    SubClientList[data.CustCode].Add(data.SubClient);
                }
            }
            if (!ConsignerList.Contains(data.ConsignerName))
            {
                ConsignerList.Add(data.ConsignerName);
            }
            if (!ConsigneeList.Contains(data.ConsigneeName))
            {
                ConsigneeList.Add(data.ConsigneeName);
            }
            if (dataContext.Where(x => x.ConsignmentNo == data.ConsignmentNo).Count() > 0)
            {
                RuntimeData origData = db.RuntimeDatas.SingleOrDefault(x => x.Id == data.Id);
                dupliData(data, origData);
            }
            else
            {
                db.RuntimeDatas.InsertOnSubmit(data);
                dataContext.Add(data);
                helper.addRecordToCurrentSheet(data);
                dataListContext.AddNewItem(data);
            }
            try
            {
                db.SubmitChanges();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); return(false); }
            return(true);
        }
Esempio n. 19
0
        private void removeduplicatePermission()
        {
            var db = new BillingDataDataContext();
            List <User_permission> temp = (from a in db.User_permissions select a).Where(x => x.emp_id == emp.Id).ToList();

            db.User_permissions.DeleteAllOnSubmit(temp);
            try
            {
                db.SubmitChanges();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); return; }
        }
Esempio n. 20
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            string             fileName = (string)e.Argument;
            CSVDataLoader      csvDL    = new CSVDataLoader();
            List <RuntimeData> data     = csvDL.getRuntimeDataFromPodCSV(fileName, '"', '\'');
            double             progress = 5;

            bg.ReportProgress((int)progress);
            double i     = 0;
            double count = data.Count;
            BillingDataDataContext db = new BillingDataDataContext();
            string errorMessage       = "";

            foreach (RuntimeData rData in data)
            {
                try
                {
                    Transaction trans = db.Transactions.SingleOrDefault(x => x.ConnsignmentNo == rData.ConsignmentNo);
                    if (trans != null)
                    {
                        trans.DeliveryDate = rData.DeliveryDate;
                        if (rData.DeliveryDate != null)
                        {
                            trans.DeliveryStatus = "Delivered";
                        }
                        trans.DeliveryTime = rData.DeliveryTime;
                        trans.ReceivedBy   = rData.ReceivedBy;
                        trans.Remarks      = trans.Remarks;
                        db.Transactions.InsertOnSubmit(trans);
                        db.SubmitChanges();
                    }
                    else
                    {
                        notFound.Add(rData);
                    }
                }
                catch
                {
                    errorMessage += rData.ConsignmentNo + " ";
                }
                i++;
                int prog = (int)(progress + (i / count * 85));
                bg.ReportProgress(prog);
            }

            e.Result = errorMessage;
            bg.ReportProgress(100);
        }
Esempio n. 21
0
 private void CostingRuleGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (e.EditAction == DataGridEditAction.Commit)
     {
         double rate;
         if (double.TryParse((e.EditingElement as TextBox).Text, out rate))
         {
             try
             {
                 BillingDataDataContext db       = new BillingDataDataContext();
                 CostingRule            origRule = e.Row.Item as CostingRule;
                 Rule newRule = db.Rules.SingleOrDefault(x => x.ID == origRule.Id);
                 if (newRule == null)
                 {
                     MessageBox.Show("Unable to find this rule in database....", "Error");
                     e.Cancel = true;
                     return;
                 }
                 JavaScriptSerializer jss = new JavaScriptSerializer();
                 CostingRule          crr = jss.Deserialize <CostingRule>(newRule.Properties);
                 if (e.Column.Header.ToString() == "Non-Dox (Rs)")
                 {
                     crr.ndoxAmount = rate;
                 }
                 if (e.Column.Header.ToString() == "Dox (Rs)")
                 {
                     crr.doxAmount = rate;
                 }
                 newRule.Properties = jss.Serialize(crr);
                 db.SubmitChanges();
             }
             catch (Exception)
             {
                 MessageBox.Show("Unable to save data....", "Error");
                 e.Cancel = true;
                 return;
             }
         }
         else
         {
             MessageBox.Show("Invalid Input.. ", "Error");
             e.Cancel = true;
         }
     }
 }
Esempio n. 22
0
        private void AddUpdate_Click(object sender, RoutedEventArgs e)
        {
            bool isdone = false;

            getfield();
            BillingDataDataContext db = new BillingDataDataContext();
            City lcity = db.Cities.SingleOrDefault(x => x.CITY_CODE == this.city.CITY_CODE);

            if (isupdate)
            {
                if (city == null)
                {
                    isupdate = false;
                }
                else
                {
                    lcity.CITY_DESC  = this.city.CITY_DESC;
                    lcity.CITY_STATE = this.city.CITY_STATE;
                    lcity.ZONE       = this.city.ZONE;
                }
            }
            if (!isupdate)
            {
                if (lcity != null)
                {
                    MessageBox.Show("A city with this code is already present....", "Error");
                    return;
                }
                city.Status = 'A';
                db.Cities.InsertOnSubmit(this.city);
            }
            try
            {
                db.SubmitChanges();
                isdone = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); isdone = false; return; }
            if (isdone)
            {
                MessageBox.Show("City Added");
                this.Close();
            }
        }
Esempio n. 23
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            string             fileName = (string)e.Argument;
            CSVDataLoader      csvDL    = new CSVDataLoader();
            List <RuntimeData> data     = csvDL.getRuntimeDataFromCSV(fileName, '"', '\'');
            double             progress = 5;

            bg.ReportProgress((int)progress);
            double i     = 0;
            double count = data.Count;
            BillingDataDataContext db = new BillingDataDataContext();
            int    sheetNo;
            string errorMessage = "";

            try
            {
                sheetNo = db.RuntimeDatas.Max(x => x.SheetNo) + 1;
            }
            catch (Exception)
            {
                sheetNo = 0;
            }
            foreach (RuntimeData rData in data)
            {
                try
                {
                    rData.SheetNo = sheetNo;
                    rData.UserId  = "System";
                    db.RuntimeDatas.InsertOnSubmit(rData);
                    db.SubmitChanges();
                }
                catch
                {
                    errorMessage += rData.ConsignmentNo + " ";
                }
                i++;
                int prog = (int)(progress + (i / count * 85));
                bg.ReportProgress(prog);
            }
            db.ImportFileData(sheetNo, "System", SecurityModule.currentUserName);
            e.Result = errorMessage;
            bg.ReportProgress(100);
        }
Esempio n. 24
0
        private void AddZoneButton_Click(object sender, RoutedEventArgs e)
        {
            string errorMsg           = "";
            BillingDataDataContext db = new BillingDataDataContext();

            if (Zonecodebox.Text == "")
            {
                errorMsg = errorMsg + "Please enter a proper zone code. \n";
            }
            else
            {
                List <ZONE> zones = db.ZONEs.Where(x => x.zcode == Zonecodebox.Text).ToList();
                if (zones.Count > 0)
                {
                    errorMsg = errorMsg + "A zone with this code already exists. \n";
                }
            }
            if (ZoneNameTextBox.Text == "")
            {
                errorMsg = errorMsg + "Please enter a proper zone name. \n";
            }
            if (errorMsg != "")
            {
                MessageBox.Show("Please correct the following errors: \n" + errorMsg);
                return;
            }
            ZONE z = new ZONE();

            z.Id        = Guid.NewGuid();
            z.Mode      = 'A';
            z.Zone_name = this.ZoneNameTextBox.Text;
            z.zcode     = this.Zonecodebox.Text;
            db.ZONEs.InsertOnSubmit(z);
            try
            {
                db.SubmitChanges();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }
        private void DeleteStockButton_Click(object sender, RoutedEventArgs e)
        {
            if (StockAssignmentDatagrid.SelectedItems.Count != 1)
            {
                MessageBox.Show("Please select delete Entry to edit.", "Info");
                return;
            }
            if (MessageBox.Show("Are you sure want to delete this entry. This cant be undone!!", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                StockAssignmentView    AssignmentEntry = (StockAssignmentView)StockAssignmentDatagrid.SelectedItem;
                BillingDataDataContext db = new BillingDataDataContext();
                Stock selectedStock       = db.Stocks.SingleOrDefault(x => x.ID == AssignmentEntry.SrlNo);
                if (selectedStock == null)
                {
                    MessageBox.Show("Selected stock doesn't exists..", "Error");
                    return;
                }

                db.Stocks.DeleteOnSubmit(selectedStock);
                db.SubmitChanges();
            }
        }
 private void DeleteRecieptButton_Click(object sender, RoutedEventArgs e)
 {
     if (PaymentGrid.SelectedItems.Count != 1)
     {
         MessageBox.Show("Please select one payment entry to delete", "Error");
         return;
     }
     if (MessageBox.Show("Are you sure you want to delete this payment entry. This operation cannot be reversed.", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         PaymentEntry           paymentEntry = (PaymentEntry)PaymentGrid.SelectedItem;
         BillingDataDataContext db           = new BillingDataDataContext();
         paymentEntry = db.PaymentEntries.SingleOrDefault(x => x.Id == paymentEntry.Id);
         if (paymentEntry == null)
         {
             MessageBox.Show("Cannot find this payment entry!!!", "Error");
             return;
         }
         db.PaymentEntries.DeleteOnSubmit(paymentEntry);
         db.SubmitChanges();
         MessageBox.Show("Entry deleted!! Please fetch again to see changes.", "Info");
     }
 }
Esempio n. 27
0
        private void AddZoneButton_Click(object sender, RoutedEventArgs e)
        {
            BillingDataDataContext db    = new BillingDataDataContext();
            List <Transaction>     trans = db.Transactions.Where(x => x.ConnsignmentNo == Zonecodebox.Text).ToList();
            List <RuntimeData>     runT  = db.RuntimeDatas.Where(x => x.ConsignmentNo == Zonecodebox.Text).ToList();
            int userCount  = runT.Select(x => x.UserId).Distinct().Count();
            int sheetCount = runT.Select(x => x.SheetNo.ToString() + x.UserId).Distinct().Count();

            if (MessageBox.Show("Transaction is loaded in " + sheetCount.ToString() + " sheets for " + userCount.ToString() + " users. Vortext must be restarted for changes to take effect. Continue?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                db.RuntimeDatas.DeleteAllOnSubmit(runT);
                db.Transactions.DeleteAllOnSubmit(trans);
                try
                {
                    db.SubmitChanges();
                    MessageBox.Show("Deleted successfully.", "Information");
                }
                catch (Exception)
                {
                    MessageBox.Show("Unable to delete transactions.", "Error");
                }
            }
        }
Esempio n. 28
0
        private void Next_Click(object sender, RoutedEventArgs e)
        {
            if (currentCanvas == 2)
            { //Data Source=SYSTEM;Initial Catalog=BillingDatabase;User ID=sa;Password=Alver!22
                constring.DataSource     = this.ServerNameBox.Text;
                constring.InitialCatalog = this.databaseBox.Text;
                constring.UserID         = this.UserNameBox.Text;
                constring.Password       = this.PasswordBox.Password;
                string            provider = "System.Data.SqlClient"; // for example
                DbProviderFactory factory  = DbProviderFactories.GetFactory(provider);
                using (DbConnection conn = factory.CreateConnection())
                {
                    conn.ConnectionString = constring.ConnectionString;
                    try
                    {
                        conn.Open();
                        isconnected = true;
                        Configs.Default.BillingDatabaseConnectionString = constring.ConnectionString;
                        Configs.Default.Save();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to connect to server"); isconnected = false; return;
                    }
                }
                MessageBox.Show("Connected successfully");
            }
            if (currentCanvas == 3)
            {
                if (this.UserPasswordBox.Password == this.UserCPasswordBox.Password)
                {
                    BillingDataDataContext db = new BillingDataDataContext(constring.ConnectionString);

                    this.emp.UserName           = this.EUserNameBox.Text;
                    this.emp.Password           = this.UserPasswordBox.Password;
                    this.emp.EMPCode            = "Super";
                    this.emp.Id                 = Guid.NewGuid();
                    this.emp.Gender             = 'M';
                    this.emp.Status             = 'A';
                    this.emp.Name               = "<none>";
                    Configs.Default.CompanyName = CompanyNameBox.Text;
                    Configs.Default.Save();
                    Employee emp = db.Employees.SingleOrDefault(x => x.UserName == this.emp.UserName);
                    if (emp != null)
                    {
                        if (!(MessageBox.Show("This employee already exists. Do you want to make this employee super on this system?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes))
                        {
                            MessageBox.Show("Please enter different employee name", "Error");
                            return;
                        }
                    }
                    else
                    {
                        db.Employees.InsertOnSubmit(emp);
                    }
                    try {
                        Configs.Default.SuperUser = this.emp.UserName;
                        Configs.Default.Save();
                        db.SubmitChanges();
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message); return; }
                }
                else
                {
                    MessageBox.Show("Password do not match", "Error"); return;
                }
            }
            switch (currentCanvas)
            {
            case 1:
                currentCanvas               = 2;
                Step1.Visibility            = Visibility.Collapsed;
                currentCanvasObj            = Step2;
                currentCanvasObj.Visibility = Visibility.Visible;
                Previous.Visibility         = Visibility.Visible;
                break;

            case 2:
                currentCanvas = 3;
                currentCanvasObj.Visibility = Visibility.Collapsed;
                currentCanvasObj            = Step3;
                currentCanvasObj.Visibility = Visibility.Visible;
                Previous.Visibility         = Visibility.Visible;
                break;

            case 3:
                currentCanvas = 4;
                currentCanvasObj.Visibility = Visibility.Collapsed;
                currentCanvasObj            = Step4;
                currentCanvasObj.Visibility = Visibility.Visible;
                Previous.Visibility         = Visibility.Collapsed;
                break;

            case 4:
                currentCanvas = 5;
                currentCanvasObj.Visibility = Visibility.Collapsed;
                currentCanvasObj            = Step5;
                currentCanvasObj.Visibility = Visibility.Visible;
                Previous.Visibility         = Visibility.Collapsed;
                break;
            }
            if (currentCanvas == 5)
            {
                Next.Visibility   = Visibility.Collapsed;
                Finish.Visibility = Visibility.Visible;
            }
            else
            {
                Next.Visibility   = Visibility.Visible;
                Finish.Visibility = Visibility.Collapsed;
            }
        }
Esempio n. 29
0
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            bool         isdone       = false;
            PaymentEntry paymentEntry = new PaymentEntry();
            string       errorMessage = "";

            paymentEntry.Id = PaymentRefNoBox.Text;
            double tempStorage;

            if (!double.TryParse(AmountTextBox.Text, out tempStorage))
            {
                errorMessage += "Amount is not in correct format. \n";
            }
            else
            {
                paymentEntry.RecievedAmount = tempStorage;
            }
            if (InvoiceSelectRadio.IsChecked == true)
            {
                Invoice invoice = (Invoice)InvoiceComboBox.SelectedItem;
                paymentEntry.InvoiceNumber = invoice.BillId;
                paymentEntry.ClientCode    = invoice.ClientCode;
            }
            else
            {
                Client client = (Client)ClientComboBox.SelectedItem;
                paymentEntry.ClientCode = client.CLCODE;
            }
            if (PaymentDatePicker.SelectedDate != null)
            {
                paymentEntry.Date = (DateTime)PaymentDatePicker.SelectedDate;
            }
            else
            {
                errorMessage += "Payment Entry Date is not Selected. \n";
            }
            if ((bool)ChequeRadio.IsChecked)
            {
                paymentEntry.Type = "Cheque";
                if (ChequeNumberBox.Text == "")
                {
                    errorMessage += "Enter the cheque number. \n";
                }
                else
                {
                    paymentEntry.ChequeNumber = ChequeNumberBox.Text;
                }
                if (ChequeBankName.Text == "")
                {
                    errorMessage += "Enter bank name: \n";
                }
                else
                {
                    paymentEntry.BankName = ChequeBankName.Text;
                }
            }
            else
            {
                paymentEntry.Type = "Cash";
            }
            paymentEntry.Remarks = RemarkBox.Text;
            if (double.TryParse(DebitNoteBox.Text, out tempStorage))
            {
                paymentEntry.DebitNote = tempStorage;
            }
            else
            {
                errorMessage += "Enter debit note properly \n";
            }
            if (double.TryParse(TDSBox.Text, out tempStorage))
            {
                paymentEntry.TDS = tempStorage;
            }
            else
            {
                errorMessage += "Enter TDS properly \n";
            }

            if (errorMessage == "")
            {
                BillingDataDataContext db = new BillingDataDataContext();
                db.PaymentEntries.InsertOnSubmit(paymentEntry);
                try
                {
                    db.SubmitChanges();
                    isdone = true;
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); isdone = false; return; }
            }
            else
            {
                MessageBox.Show("Please correct the following errors: \n" + errorMessage);
            }
            if (isdone)
            {
                MessageBox.Show("Payment Received\nReference no is " + paymentEntry.Id);
                fillFields();
            }
        }
Esempio n. 30
0
        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();
                    }
                }
            }
        }