Ejemplo n.º 1
0
        private int AddTerritory()
        {
            Cursor.Current = Cursors.WaitCursor;
            SalesTerritory st = new SalesTerritory();
            int            id = 0;

            try
            {
                string territory = txtTerritory.Text.Trim();
                st.Name              = territory;
                st.ModifiedDate      = DateTime.Now;
                st.CountryRegionCode = string.Empty;
                id = st.AddSalesTerritory(st);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message, "Sales Territory", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
            return(id);
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            SalesTerritory        st   = new SalesTerritory();
            SalesTerritoryHistory hist = new SalesTerritoryHistory();

            try
            {
                if (txtName.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("Please enter territory name", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                if (cmbSalesPerson.Items.Count == 0)
                {
                    btnSave.Enabled = false;
                }
                else
                {
                    btnSave.Enabled = true;
                }
                if (cmbSalesPerson.SelectedIndex == 0)
                {
                    MessageBox.Show("Please select a sale person", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                st.Name = txtName.Text;
                st.CountryRegionCode = txtCounty.Text;

                if (txtTerritoryID.Text.Trim() == String.Empty)
                {
                    //new record
                    hist.TerritoryID   = st.AddSalesTerritory(st);
                    hist.SalesPersonID = Int32.Parse(cmbSalesPerson.SelectedValue.ToString());
                    hist.StartDate     = dtStartDate.Value;
                    //hist.EndDate = null;
                    hist.AddSalesTerritoryHistory(hist);
                    MessageBox.Show("Record saved successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //existing record, update territory and territory history
                    st.TerritoryID = Int32.Parse(txtTerritoryID.Text);
                    st.UpdateSalesTerritory(st);

                    hist.ID = m_currentHistoryId;

                    hist.SalesPersonID = Int32.Parse(cmbSalesPerson.SelectedValue.ToString());
                    hist.TerritoryID   = st.TerritoryID;
                    hist.StartDate     = dtStartDate.Value;
                    //hist.EndDate = dtEndDate.Value;
                    hist.UpdateSalesTerritoryHistory(hist);
                    //hist.AddSalesTerritoryHistory(hist);
                    MessageBox.Show("Record saved successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                RefreshForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MICS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                st = null;
            }
        }