private void Update_contact() { DataTable dttable_contact = (DataTable)grd_contact.DataSource; using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.VehicleDealershipConnectionString)) { conn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn)) { bulkCopy.DestinationTableName = "[misc].[bulkcopy_table]"; Bulkcopy_table_ds.Delete_by_user(); try { DataColumn dt_col1 = new DataColumn("modified_by", typeof(int)); dt_col1.DefaultValue = Program.System_user.UserID; dttable_contact.Columns.Add(dt_col1); bulkCopy.ColumnMappings.Add("contact", "nvarchar1"); bulkCopy.ColumnMappings.Add("remark", "nvarchar2"); bulkCopy.ColumnMappings.Add("modified_by", "created_by"); bulkCopy.WriteToServer(dttable_contact); Organisation_contact_ds.Update_insert_organisation_contact(OrganisationID); } catch (Exception ex) { MessageBox.Show("An error has occurred. Contact cannot be updated. \n\n Message: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } conn.Close(); } }
public override global::System.Data.DataSet Clone() { Bulkcopy_table_ds cln = ((Bulkcopy_table_ds)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { Bulkcopy_table_ds ds = new Bulkcopy_table_ds(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
private void Update_branch() { DataTable dttable_branch = (DataTable)grd_branch.DataSource; using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.VehicleDealershipConnectionString)) { conn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn)) { bulkCopy.DestinationTableName = "[misc].[bulkcopy_table]"; // upload branch information Bulkcopy_table_ds.Delete_by_user(); try { DataColumn dt_col1 = new DataColumn("modified_by", typeof(int)); dt_col1.DefaultValue = Program.System_user.UserID; dttable_branch.Columns.Add(dt_col1); bulkCopy.ColumnMappings.Clear(); bulkCopy.ColumnMappings.Add("branch_name", "nvarchar1"); bulkCopy.ColumnMappings.Add("address", "nvarchar2"); bulkCopy.ColumnMappings.Add("city", "nvarchar3"); bulkCopy.ColumnMappings.Add("state", "nvarchar4"); bulkCopy.ColumnMappings.Add("postcode", "nvarchar5"); bulkCopy.ColumnMappings.Add("organisation_branch", "int1"); bulkCopy.ColumnMappings.Add("country", "int2"); bulkCopy.ColumnMappings.Add("modified_by", "created_by"); bulkCopy.WriteToServer(dttable_branch); Organisation_branch_ds.Update_insert_organisation_branch(OrganisationID); } catch (Exception ex) { MessageBox.Show("An error has occurred. Branch cannot be updated. \n\n Message: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } conn.Close(); } }
private void Btn_ok_Click(object sender, EventArgs e) { if (!Program.System_user.Has_permission(Class_enum.User_permission.ADD_EDIT_PERSON)) { this.DialogResult = DialogResult.Cancel; this.Close(); return; } if (txt_name.Text.Trim() == "" || txt_ic_no.Text.Trim() == "") { MessageBox.Show("Name and IC no. are required.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Person_contact_ds.sp_select_person_contactDataTable dttable_contact = (Person_contact_ds.sp_select_person_contactDataTable)grd_contact.DataSource; dttable_contact.AcceptChanges(); // must use row["remark"] instead of row.remark because row.remarks is string type and cannot be dbnull. row["remark"] is object type and can be dbnull var query_check_empty = from row in dttable_contact where row.contact.Trim() == "" && (row["remark"] != DBNull.Value && row.remark.Trim() != "") select row; if (query_check_empty.Count() > 0) { MessageBox.Show("Contact cannot be empty. Please check and retry.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var query_contact = from row in dttable_contact group row by row.contact into grp where grp.Count() > 1 select grp.Key; if (query_contact.Count() > 0) { MessageBox.Show("Duplicate contact detected. Please check and retry.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // set byte image to null if no image. null value will set db column to null byte[] byte_image = null; if (picbox_image.Image != null) { Image img = picbox_image.Image; using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte_image = ms.ToArray(); } } if (PersonID == 0) { // insert PersonID = Person_ds.Insert_person(txt_name.Text.Trim(), txt_ic_no.Text.Trim(), byte_image, (int)cmb_type.SelectedValue, txt_driving_license.Text.Trim(), (cmb_gender.SelectedValue.ToString() == "MALE"), (int)cmb_race.SelectedValue, txt_address.Text.Trim(), txt_city.Text.Trim(), txt_state.Text.Trim(), txt_postcode.Text.Trim(), (short)cmb_country.SelectedValue, txt_occupation.Text.Trim(), txt_company.Text.Trim(), txt_url.Text.Trim()); } else { // update Person_ds.Update_person(PersonID, txt_name.Text.Trim(), txt_ic_no.Text.Trim(), byte_image, (int)cmb_type.SelectedValue, txt_driving_license.Text.Trim(), (cmb_gender.SelectedValue.ToString() == "MALE"), (int)cmb_race.SelectedValue, txt_address.Text.Trim(), txt_city.Text.Trim(), txt_state.Text.Trim(), txt_postcode.Text.Trim(), (short)cmb_country.SelectedValue, txt_occupation.Text.Trim(), txt_company.Text.Trim(), txt_url.Text.Trim()); } // at this point, personID must be positive integer. if (PersonID == 0) { MessageBox.Show("An error has occurred.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // upload contact information DataColumn dt_col1 = new DataColumn("modified_by", typeof(int)) { DefaultValue = Program.System_user.UserID }; dttable_contact.Columns.Add(dt_col1); Bulkcopy_table_ds.Delete_by_user(); using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.VehicleDealershipConnectionString)) { conn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn)) { bulkCopy.DestinationTableName = "[misc].[bulkcopy_table]"; try { bulkCopy.ColumnMappings.Add("contact", "nvarchar1"); bulkCopy.ColumnMappings.Add("remark", "nvarchar2"); bulkCopy.ColumnMappings.Add("modified_by", "created_by"); bulkCopy.WriteToServer(dttable_contact); } catch (Exception ex) { MessageBox.Show("An error has occurred. Vehicle groups cannot be updated. \n\n Message: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } conn.Close(); } Person_contact_ds.Update_insert_person_contact(PersonID); this.DialogResult = DialogResult.OK; this.Close(); }
private void Btn_ok_Click(object sender, EventArgs e) { // reset all grd_group rows back color foreach (DataGridViewRow grd_row in grd_main.Rows) { if (!grd_row.IsNewRow) { grd_row.DefaultCellStyle.BackColor = Color.Empty; } } string str_brand_name = txt_name.Text.Trim(); if (str_brand_name == "") { MessageBox.Show("Brand name is required!", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cmb1.SelectedIndex < 0) { MessageBox.Show("Please select a country.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int int_country = int.Parse(cmb1.SelectedValue.ToString()); if (!Vehicle_brand_ds.Is_vehicle_brand_name_available(str_brand_name, _int_brand_id)) { MessageBox.Show("Brand name already exists! Please input new brand name.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DataTable dttable_vehicle_group = ((DataTable)grd_main.DataSource).Copy(); if (dttable_vehicle_group.Rows.Count == 0) { MessageBox.Show("At least one vehicle group is required.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int distinct_group_name_count = (from DataRow row in dttable_vehicle_group.Rows select row["vehicle_group_name"].ToString().ToUpper()).Distinct().ToList().Count; if (distinct_group_name_count != dttable_vehicle_group.Rows.Count) { MessageBox.Show("Duplicate vehicle group found. Please check and retry.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_int_brand_id == 0) { _int_brand_id = Vehicle_brand_ds.Insert_vehicle_brand(str_brand_name, int_country); } else { Vehicle_brand_ds.Update_vehicle_brand(_int_brand_id, str_brand_name, int_country); } DataColumn dt_col1 = new DataColumn("Created_by", typeof(int)) { DefaultValue = Program.System_user.UserID }; dttable_vehicle_group.Columns.Add(dt_col1); Bulkcopy_table_ds.Delete_by_user(); using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.VehicleDealershipConnectionString)) { conn.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn)) { bulkCopy.DestinationTableName = "[misc].[bulkcopy_table]"; try { bulkCopy.ColumnMappings.Add("vehicle_group", "vehicle_group"); bulkCopy.ColumnMappings.Add("vehicle_group_name", "vehicle_group_name"); bulkCopy.ColumnMappings.Add("created_by", "created_by"); bulkCopy.WriteToServer(dttable_vehicle_group); } catch (Exception ex) { MessageBox.Show("An error has occurred. Vehicle groups cannot be updated. \n\n Message: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } conn.Close(); } Vehicle_group_ds.Update_insert_vehicle_group(_int_brand_id); this.DialogResult = DialogResult.OK; this.Close(); }