コード例 #1
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (ls_CasNumber.C_CasNumber == null || txt_percent.Text == "")
            {
                Util.ShowError("Cas# and Percent are required.");
                return;
            }

            try
            {
                Int32 zz = Int32.Parse(txt_percent.Text);

                if (zz == 0)
                {
                    throw new Exception();
                }
            }
            catch
            {
                Util.ShowError("Please enter a valid number.");
                return;
            }


            if (RecordList != null)
            {
                if ((RecordList.Sum(f => f.Percent) + Int32.Parse(txt_percent.Text)) > 100)
                {
                    Util.ShowError("Percent can't pass to 100%.");
                    return;
                }
            }

            /*if (service.GetC_CasNumberFormula(new C_CasNumberFormula { CasNumberComponent = (C_CasNumber)ls_CasNumber.SelectedItem }) != null)
             * {
             *  Util.ShowError("Cas# already selected");
             *  return;
             * }*/

            try
            {
                //Guardo el registro
                Record.CreatedBy          = App.curUser.UserName;
                Record.CreationDate       = DateTime.Now;
                Record.CasNumberComponent = (C_CasNumber)ls_CasNumber.C_CasNumber;
                Record.Product            = this.Product;
                Record = service.SaveC_CasNumberFormula(Record);

                //Obteniendo la lista con el nuevo dato
                LoadExistingList();

                //reinicio los campos para adicionar nuevos datos
                txt_percent.Text = "";

                Util.ShowMessage("Record Created.");
            }
            catch (Exception ex)
            {
                Util.ShowError("Problem creating record.\n" + ex.Message);
                txt_percent.Text = "";
                return;
            }
        }