Beispiel #1
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();
        }
        public AddServiceRule(int ruleId)
            : this()
        {
            this.isUpdate = true;
            BillingDataDataContext db = new BillingDataDataContext();

            db   = new BillingDataDataContext();
            rule = db.Rules.SingleOrDefault(x => x.ID == ruleId);
            if (rule == null)
            {
                MessageBox.Show("Invalid Rule.");
                return;
            }
            isInitialized           = true;
            SRule                   = RuleSR = (new JavaScriptSerializer()).Deserialize <ServiceRule>(rule.Properties);
            this.FromWeightBox.Text = SRule.startW.ToString();
            this.ToWeightBox.Text   = SRule.endW.ToString();
            if (SRule.type == 'W')
            {
                this.WholeRadio.IsChecked = true;
                this.StepRadio.IsChecked  = false;
            }
            else
            {
                this.WholeRadio.IsChecked = false;
                this.StepRadio.IsChecked  = true;
                this.StepBox.Text         = SRule.stepweight.ToString();
            }
            if (SRule.change == 'I')
            {
                this.IncRadio.IsChecked = true;
            }
            else
            {
                this.DecRadio.IsChecked = true;
            }
            if (SRule.mode == 'P')
            {
                this.PerRadio.IsChecked = true;
                this.ValueBox.Text      = SRule.per.ToString();
            }
            else
            {
                this.AmountRadio.IsChecked = true;
                this.AmountBox.Text        = SRule.per.ToString();
            }
            AddRule.setFormList(SRule, this.ServiceTwinBox, this.ZoneTwinBox, this.StateTwinBox, this.CitiesTwinBox, ServiceGroupTwinBox);
            this.RemarkBox.Text        = rule.Remark;
            this.AddFilter.Data        = Geometry.Parse(@"F1M2,12.942C2,12.942 10.226,15.241 10.226,15.241 10.226,15.241 8.275,17.071 8.275,17.071 9.288,17.922 10.917,18.786 12.32,18.786 15.074,18.786 17.386,16.824 18.039,14.171 18.039,14.171 21.987,15.222 21.987,15.222 20.891,19.693 16.996,23 12.357,23 9.771,23 7.076,21.618 5.308,19.934 5.308,19.934 3.454,21.671 3.454,21.671 3.454,21.671 2,12.942 2,12.942z M11.643,2C14.229,2 16.924,3.382 18.692,5.066 18.692,5.066 20.546,3.329 20.546,3.329 20.546,3.329 22,12.058 22,12.058 22,12.058 13.774,9.759 13.774,9.759 13.774,9.759 15.725,7.929 15.725,7.929 14.712,7.078 13.083,6.214 11.68,6.214 8.926,6.214 6.614,8.176 5.961,10.829 5.961,10.829 2.013,9.778 2.013,9.778 3.109,5.307 7.004,2 11.643,2z");
            this.AddFilter.Height      = 18;
            this.AddFilter.Width       = 18;
            this.Title                 = "Update Rule " + ruleId.ToString();
            this.AddRuleButtonBox.Text = " Update Rule";
        }
        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();
                }
            }
        }