public int SaveTerritoryManagement(TerritoryManagers aManagers) { con = new SqlConnection(cs.DBConn); con.Open(); string query = "INSERT INTO TerritoryManager(UserId,TerritoryId,OndutyForm,AssginedBy) VALUES(@d1,@d2,@d3,@d4)"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@d1", aManagers.TMUserId); cmd.Parameters.AddWithValue("@d2", aManagers.TerritoryId); cmd.Parameters.AddWithValue("@d3", aManagers.OnDutyFrom); cmd.Parameters.AddWithValue("@d4", aManagers.AssignedBy); int affectedRows = cmd.ExecuteNonQuery(); con.Close(); return(affectedRows); }
private void saveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtTerritoryManager.Text)) { MessageBox.Show("Please Select Territory Manager Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(txtTerritoryName.Text)) { MessageBox.Show("Please Select Territory Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { con = new SqlConnection(cs.DBConn); con.Open(); string ct2 = "select TerritoryManager.TerritoryId from TerritoryManager where TerritoryManager.TerritoryId='" + territoryId + "' and OffDutydate is null"; cmd = new SqlCommand(ct2, con); rdr = cmd.ExecuteReader(); if (!rdr.Read()) { int tm = 0; TerritoryManagerManager aManager = new TerritoryManagerManager(); TerritoryManagers aManagers = new TerritoryManagers(); aManagers.TMUserId = userIdAsTM.ToString(); aManagers.TerritoryId = territoryId.ToString(); aManagers.OnDutyFrom = txtAssignedDate.Value; aManagers.AssignedBy = userId; tm = aManager.SaveTerritoryManagement(aManagers); MessageBox.Show("Successfully Created", "record", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } else { MessageBox.Show("This Territory already under one Territory manager", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int SaveTerritoryManagement(TerritoryManagers aManagers) { return(aGateway.SaveTerritoryManagement(aManagers)); }