The Visual C# .Net Form - book_note.cs, Text Codes
 
 
 

       
      Return



  The Form -  book_note.cs ...

 
 

 The codes  corresponding ...
   
    
   The text Code is red color, the codes added manuel
 
 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace work_VCnet

{

/// <summary>

/// Summary description for book_note.

/// </summary>

public class book_note : System.Windows.Forms.Form

{

private System.Data.OleDb.OleDbConnection oleDbConnection1;

private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

private work_VCnet.book_dset objbook_dset;

internal System.Data.OleDb.OleDbCommand OleDbCommand2;

internal System.Windows.Forms.Panel Panel5;

internal System.Windows.Forms.TextBox editcity;

internal System.Windows.Forms.TextBox editcountry;

internal System.Windows.Forms.ComboBox cmbcity;

internal System.Windows.Forms.ComboBox cmbcountry;

internal System.Windows.Forms.Label lblpost_office_box;

internal System.Windows.Forms.TextBox editpost_office_box;

internal System.Windows.Forms.Label lblcity;

internal System.Windows.Forms.Label lblcountry;

internal System.Windows.Forms.TabControl TabControl1;

internal System.Windows.Forms.TabPage TabPage1;

internal System.Windows.Forms.TextBox editaddress1;

internal System.Windows.Forms.TabPage TabPage2;

internal System.Windows.Forms.TextBox editaddress2;

internal System.Windows.Forms.PictureBox PictureBox3;

internal System.Windows.Forms.ToolBarButton ToolBarprint;

internal System.Windows.Forms.ImageList ImageList1;

internal System.Windows.Forms.ToolBarButton ToolBarclose;

internal System.Windows.Forms.ToolBarButton ToolBarsearch;

internal System.Windows.Forms.Panel Panel41;

internal System.Windows.Forms.PictureBox Pic_line01;

internal System.Windows.Forms.Panel Panel7;

internal System.Windows.Forms.PictureBox PictureBox4;

internal System.Windows.Forms.Label ltoday;

internal System.Data.OleDb.OleDbCommand OleDbCommand4;

internal System.Windows.Forms.Panel Panel1;

internal System.Data.OleDb.OleDbCommand oleDbCommand1;

internal System.Data.OleDb.OleDbCommand oleDbCommand3;

internal System.Data.OleDb.OleDbCommand oleDbCommand5;

internal System.Windows.Forms.Panel Panel6;

internal System.Windows.Forms.Label lblalternativePhone;

internal System.Windows.Forms.Label lblemail;

internal System.Windows.Forms.Label lblfax;

internal System.Windows.Forms.TextBox editalternativePhone;

internal System.Windows.Forms.TextBox editemail;

internal System.Windows.Forms.TextBox editfax;

internal System.Windows.Forms.Label lblhomephone;

internal System.Windows.Forms.Label lblmobilephone;

internal System.Windows.Forms.Label lblweb;

internal System.Windows.Forms.Label lblworkphone;

internal System.Windows.Forms.TextBox edithomephone;

internal System.Windows.Forms.TextBox editmobilephone;

internal System.Windows.Forms.TextBox editweb;

internal System.Windows.Forms.TextBox editworkphone;

internal System.Windows.Forms.PictureBox PictureBox1;

internal System.Data.OleDb.OleDbCommand oleDbCommand6;

internal System.Windows.Forms.Panel Panel4;

internal System.Windows.Forms.Panel Panel_photo;

internal System.Windows.Forms.TextBox editphoto_photo;

internal System.Windows.Forms.PictureBox Pic_photo;

internal System.Windows.Forms.Button Btnphoto_new;

internal System.Windows.Forms.Button Btnphoto_del;

internal System.Windows.Forms.TextBox editoriginalfirst_name;

internal System.Windows.Forms.TextBox editbirth_y;

internal System.Windows.Forms.TextBox editbirth_m;

internal System.Windows.Forms.TextBox editbirth_d;

internal System.Windows.Forms.TextBox editbirth;

internal System.Windows.Forms.TextBox editcivil_status;

internal System.Windows.Forms.TextBox editfather_name;

internal System.Windows.Forms.TextBox editfirst_name;

internal System.Windows.Forms.TextBox editname;

internal System.Windows.Forms.TextBox editsex;

internal System.Windows.Forms.DateTimePicker DateTime_birth;

internal System.Windows.Forms.ComboBox cmbcivil_status;

internal System.Windows.Forms.ComboBox cmbfather_name;

internal System.Windows.Forms.ComboBox cmbfirst_name;

internal System.Windows.Forms.ComboBox cmbname;

internal System.Windows.Forms.ComboBox cmbsex;

internal System.Windows.Forms.Label lblfunction;

internal System.Windows.Forms.TextBox editfunction;

internal System.Windows.Forms.Label lblbirth;

internal System.Windows.Forms.Label lblcivil_status;

internal System.Windows.Forms.Label lblfather_name;

internal System.Windows.Forms.Label lblfirst_name;

internal System.Windows.Forms.Label lblname;

internal System.Windows.Forms.Label lblsex;

internal System.Windows.Forms.PictureBox PictureBox2;

internal System.Windows.Forms.ImageList ImageList00;

internal System.Windows.Forms.Panel Panel42;

internal System.Windows.Forms.PictureBox Pic_line02;

internal System.Data.OleDb.OleDbCommand oleDbCommand7;

internal System.Windows.Forms.Panel Panel2;

internal System.Windows.Forms.Panel Panel21;

internal System.Windows.Forms.Panel Panel22;

internal System.Windows.Forms.Label lboperation;

internal System.Windows.Forms.Label lblNavLocation;

internal System.Data.OleDb.OleDbCommand oleDbCommand8;

internal System.Windows.Forms.ToolBarButton ToolBarcancel;

internal System.Windows.Forms.ToolBarButton ToolBarsave;

internal System.Windows.Forms.ToolBarButton ToolBarmodify;

internal System.Windows.Forms.ToolBarButton ToolBaradd;

internal System.Windows.Forms.ToolBarButton ToolBarnext;

internal System.Windows.Forms.ToolBarButton ToolBarlast;

internal System.Windows.Forms.ToolBarButton ToolBarfirst;

internal System.Windows.Forms.ToolBarButton ToolBarpreview;

internal System.Windows.Forms.Panel Panel91;

internal System.Windows.Forms.Panel Panel43;

internal System.Windows.Forms.OpenFileDialog OpenFileDialog1;

internal System.Windows.Forms.Panel Panel3;

internal System.Windows.Forms.PictureBox Pic_book;

internal System.Windows.Forms.Panel Panel31;

internal System.Windows.Forms.Panel Panel312;

internal System.Windows.Forms.ToolBar ToolBar2;

internal System.Windows.Forms.Panel Panel311;

internal System.Windows.Forms.ToolBar ToolBar1;

internal System.Windows.Forms.Panel Panel32;

internal System.Windows.Forms.Panel Panel324;

internal System.Windows.Forms.ToolBar ToolBar6;

internal System.Windows.Forms.Panel Panel323;

internal System.Windows.Forms.ToolBar ToolBar5;

internal System.Windows.Forms.Panel Panel322;

internal System.Windows.Forms.ToolBar ToolBar4;

internal System.Windows.Forms.Panel Panel321;

internal System.Windows.Forms.ToolBar ToolBar3;

internal System.Windows.Forms.Panel Panel33;

internal System.Windows.Forms.Panel Panel333;

internal System.Windows.Forms.ToolBar ToolBar9;

internal System.Windows.Forms.Panel Panel332;

internal System.Windows.Forms.ToolBar ToolBar8;

internal System.Windows.Forms.Panel Panel331;

internal System.Windows.Forms.ToolBar ToolBar7;

private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

 

private System.ComponentModel.IContainer components;

//variable

//Select command

System.Data.OleDb.OleDbCommand vselect1;

//Dataadapter

System.Data.OleDb.OleDbDataAdapter vda1;

System.Data.DataSet vdset1;

bool mbeditflag;

bool mbaddflag;

public book_note()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}


 

      Windows Form Designer generated code


 

//list of operations available: navigation, add/new, modify, update, cancel, find/search, print, close

// public variables

public class book_note_cl

{

public static string booknote_type;

public static int booknote_width;

public static int booknote_left;

public static int booknote_top;

}

private void book_note_Load(object sender, System.EventArgs e)

{

//move

this.editphoto_photo.Top = -this.editphoto_photo.Height;

//resize

this.Panel21.Top = (this.Panel2.Height - this.Panel21.Height) / 2;

this.Panel22.Left = (this.Panel21.Width - this.Panel22.Width) / 2;

this.lblNavLocation.Width = this.Panel22.Left - 16;

this.lblNavLocation.Left = (this.Panel22.Left - this.lblNavLocation.Width) / 2;

this.lblNavLocation.Top = 0;

this.lboperation.Width = this.lblNavLocation.Width;

this.lboperation.Left = this.Panel22.Left + (this.Panel22.Left - this.lblNavLocation.Width) / 2;

this.lboperation.Top = this.lblNavLocation.Top;

this.Panel91.Top = this.Panel4.Top;

this.Panel41.Left = this.Panel91.Left;

this.Panel42.Left = this.Panel91.Left;

this.Panel91.Height = this.Panel4.Height + this.Panel41.Height + this.Panel5.Height + this.Panel42.Height + this.Panel6.Height;

this.Panel41.Top = this.Panel4.Top + this.Panel4.Height;

this.Panel5.Top = this.Panel41.Top + this.Panel41.Height;

this.Panel42.Top = this.Panel5.Top + this.Panel5.Height;

this.Panel6.Top = this.Panel42.Top + this.Panel42.Height;

this.Panel43.Top = this.Panel6.Top + this.Panel6.Height;

this.Panel5.Left = this.Panel4.Left;

this.Panel6.Left = this.Panel4.Left;

this.Pic_line01.Width = this.Panel4.Width;

this.Pic_line01.Left = this.Panel91.Width;

this.Pic_line02.Width = this.Pic_line01.Width;

this.Pic_line02.Left = this.Pic_line01.Left;

this.Panel3.Height = this.Panel43.Top - 8;

this.Panel3.Top = 4;

this.Pic_book.Left = (this.Panel3.Width - this.Pic_book.Width) / 2;

this.Pic_book.Top = this.Panel33.Top + this.Panel33.Height + (this.Panel3.Height - (this.Panel33.Top + this.Panel33.Height + this.Pic_book.Height)) / 2;

book_note_cl.booknote_width = this.Width;

book_note_cl.booknote_left = this.Left;

book_note_cl.booknote_top= this.Top;

 

//load book table, objbook_dset dataset

LoadDataSet();

book_note_cl.booknote_type = "";

mbeditflag = false;

mbaddflag = false;

sub_load("name");

sub_load("first");

sub_load("father");

sub_load("city");

sub_load("civil_status");

this.ltoday.Text = DateTime.Today.ToLongDateString();

NavFirst();

}

//load book table, objbook_dset dataset

public void LoadDataSet()

{

try

{

// Attempt to load the dataset.

this.LoadDataSet1();

}

catch (System.Exception eLoad)

{

// Add your error

System.Windows.Forms.MessageBox.Show(eLoad.Message);

}

}

public void LoadDataSet1()

{

// Create a new dataset to hold the records returned from the call to FillDataSet.

// A temporary dataset is used because filling the existing dataset would

// require the databindings to be rebound.

work_VCnet.book_dset objDataSetTemp;

objDataSetTemp = new work_VCnet.book_dset();

try

{

// Attempt to fill the temporary dataset.

this.FillDataSet(objDataSetTemp);

}

catch (System.Exception eFillDataSet)

{

// Add your error handling code here.

throw eFillDataSet;

}

try

{

// Empty the old records from the dataset.

objbook_dset.Clear();

// Merge the records into the main dataset.

objbook_dset.Merge(objDataSetTemp);

}

catch (System.Exception eLoadMerge)

{

// Add your error handling code here.

throw eLoadMerge;

}

}

public void FillDataSet(work_VCnet.book_dset dataSet)

{

// Turn off constraint checking before the dataset is filled.

// This allows the adapters to fill the dataset without concern

// for dependencies between the tables.

dataSet.EnforceConstraints = false;

try

{

// Open the connection.

this.oleDbConnection1.Open();

// Attempt to fill the dataset through the OleDbDataAdapter1.

this.oleDbDataAdapter1.Fill(dataSet);

}

catch (System.Exception fillException)

{

// Add your error handling code here.

throw fillException;

}

finally

{

// Turn constraint checking back on.

dataSet.EnforceConstraints = true;

// Close the connection whether or not the exception was thrown.

this.oleDbConnection1.Close();

}

}

//add data to comboboxes

private void sub_load(string v_field)

{

int i;

switch(v_field)

{

case "name":

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(name) AS vname FROM book WHERE (Trim(name) <> '') ORDER BY Trim(name)");

break;

case "first":

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(first_name) AS vfirst FROM book WHERE (Trim(first_name) <>'')ORDER BY Trim(first_name)");

break;

case "father":

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(father_name) AS vfather FROM book WHERE (Trim(father_name) <>'')ORDER BY Trim(father_name)");

break;

case "city":

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(city) AS vcity FROM book WHERE (Trim(city)<>'')ORDER BY Trim(city)");

break;

case "civil_status":

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT DISTINCT Trim(civil_status) AS vcivil FROM book WHERE (Trim(civil_status) <>'')ORDER BY Trim(civil_status)");

break;

}

vda1 = new System.Data.OleDb.OleDbDataAdapter(vselect1);

vdset1 = new System.Data.DataSet();

vselect1.Connection = this.oleDbConnection1;

vdset1.EnforceConstraints = false;

try

{

this.oleDbConnection1.Open();

vda1.Fill(vdset1, "book");

}

catch (System.Exception fillException)

{

System.Windows.Forms.MessageBox.Show(fillException.Message);

}

vdset1.EnforceConstraints = true;

this.oleDbConnection1.Close();

if (vdset1.Tables["book"].Rows.Count > 0)

{

for (i = 0 ; i <= (vdset1.Tables["book"].Rows.Count - 1); i++)

{

switch(v_field)

{

case "name":

this.cmbname.Items.Add(vdset1.Tables["book"].Rows[i]["vname"].ToString().Trim());

break;

case "first":

this.cmbfirst_name.Items.Add(vdset1.Tables["book"].Rows[i]["vfirst"].ToString().Trim());

break;

case "father":

this.cmbfather_name.Items.Add(vdset1.Tables["book"].Rows[i]["vfather"].ToString().Trim());

break;

case "city":

this.cmbcity.Items.Add(vdset1.Tables["book"].Rows[i]["vcity"].ToString().Trim());

break;

case "civil_status":

this.cmbcivil_status.Items.Add(vdset1.Tables["book"].Rows[i]["vcivil"].ToString().Trim());

break;

}

}

}

}

 

private void book_note_Closed(object sender, System.EventArgs e)

{

if ((mbaddflag == true) || (mbeditflag == true))

{

this.close_response();

}

//else

//{

// this.Close();

//}

}

private void close_response()

{

System.Windows.Forms.DialogResult response;

string msg_inf;

msg_inf = "are you sure want to lose all changes, book note ...";

response = MessageBox.Show(msg_inf, work_VCnet.mainform.mainform_cl.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

//Gets the result of the MessageBox display.

if (response == DialogResult.Yes)

{

mbaddflag = false;

mbeditflag = false;

this.Close();

}

}

private void ToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar1.Buttons.IndexOf(e.Button))

{

//first

case 0:

this.NavFirst();

break;

//preview

case 1:

this.NavPrev();

break;

}

}

private void ToolBar2_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar2.Buttons.IndexOf(e.Button))

{

//next

case 0:

this.NavNext();

break;

//last

case 1:

this.NavLast();

break;

}

}

private void ToolBar3_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar3.Buttons.IndexOf(e.Button))

{

//add

case 0:

this.sub_add();

break;

}

}

private void ToolBar4_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar4.Buttons.IndexOf(e.Button))

{

//modify

case 0:

this.sub_modify();

break;

//save

}

}

private void ToolBar5_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar5.Buttons.IndexOf(e.Button))

{

//save

case 0:

this.sub_Update();

break;

}

}

private void ToolBar6_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar6.Buttons.IndexOf(e.Button))

{

//cancel

case 0:

this.sub_Cancel();

break;

}

}

private void ToolBar7_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar7.Buttons.IndexOf(e.Button))

{

//search

case 0:

this.sub_find();

break;

}

}

private void ToolBar8_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar8.Buttons.IndexOf(e.Button))

{

//print

case 0:

this.sub_print();

break;

}

}

private void ToolBar9_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(this.ToolBar9.Buttons.IndexOf(e.Button))

{

//close form

case 0:

if ((mbaddflag == true) || (mbeditflag == true))

{

this.close_response();

}

else

{

this.Close();

}

break;

}

}

//navigation operation ... *****************************

private void NavFirst()

{

this.BindingContext[objbook_dset,"book"].Position = 0;

this.objbook_dset_PositionChanged();

}

private void objbook_dset_PositionChanged()

{

this.editbirth.Text = System.Convert.ToString(this.DateTime_birth.Value.Month) + "/" + System.Convert.ToString(this.DateTime_birth.Value.Day) + "/" + System.Convert.ToString(this.DateTime_birth.Value.Year);

this.lblNavLocation.Text = ((((this.BindingContext[objbook_dset,"book"].Position + 1)).ToString() + " of ")

+ this.BindingContext[objbook_dset,"book"].Count.ToString());

switch(mbaddflag || mbeditflag)

{

case false:

visible_control(false);

// Navigation controls enabled

if ((this.BindingContext[objbook_dset,"book"].Position + 1) == 1)

{

NavigationFP(false);

NavigationNL(true);

goto PP1;

}

if ((this.BindingContext[objbook_dset,"book"].Position +1) == (this.BindingContext[objbook_dset,"book"].Count))

{

NavigationFP(true);

NavigationNL(false);

goto PP1;

}

else

{

NavigationFP(true);

NavigationNL(true);

}

PP1:

if (this.ToolBaradd.Enabled == false)

Enabled_AMS(true);

if (this.ToolBarsearch.Enabled == false)

Enabled_CFP(true);

break;

case true:

if (mbaddflag == true)

lboperation.Text = "add operation";

if (mbeditflag == true)

this.lboperation.Text = "mudify operation";

visible_control(true);

NavigationFP(false);

NavigationNL(false);

Enabled_AMS(false);

Enabled_CFP(false);

//if (this.ToolBarsave.Enabled == false)

// this.ToolBarsave.Enabled = true;

//if (this.ToolBarcancel.Enabled == false)

// this.ToolBarcancel.Enabled = true;

break;

}

//show photo

sub_showphoto();

this.lblNavLocation.Focus();

}

private void visible_control( bool bval)

{

this.cmbname.Visible = bval;

this.cmbfirst_name.Visible = bval;

this.cmbfather_name.Visible = bval;

this.DateTime_birth.Visible = bval;

this.cmbsex.Visible = bval;

this.cmbcivil_status.Visible = bval;

this.cmbcountry.Visible = bval;

this.cmbcity.Visible = bval;

this.editname.Visible = !bval;

this.editfirst_name.Visible = !bval;

this.editfather_name.Visible = !bval;

this.editbirth.Visible = !bval;

this.editcivil_status.Visible = !bval;

this.editsex.Visible = !bval;

this.editcountry.Visible = !bval;

this.editcity.Visible = !bval;

this.editname.Left = this.cmbname.Left;

this.editname.Width = this.cmbname.Width;

this.editname.Top = this.cmbname.Top;

this.editfirst_name.Left = this.cmbfirst_name.Left;

this.editfirst_name.Width = this.cmbfirst_name.Width;

this.editfirst_name.Top = this.cmbfirst_name.Top;

this.editfather_name.Left = this.cmbfather_name.Left;

this.editfather_name.Width = this.cmbfather_name.Width;

this.editfather_name.Top = this.cmbfather_name.Top;

this.editbirth.Left = this.DateTime_birth.Left;

this.editbirth.Width = this.DateTime_birth.Width;

this.editbirth.Top = this.DateTime_birth.Top;

this.editsex.Left = this.cmbsex.Left;

this.editsex.Width = this.cmbsex.Width;

this.editsex.Top = this.cmbsex.Top;

this.editcivil_status.Left = this.cmbcivil_status.Left;

this.editcivil_status.Width = this.cmbcivil_status.Width;

this.editcivil_status.Top = this.cmbcivil_status.Top;

this.editcountry.Left = this.cmbcountry.Left;

this.editcountry.Width = this.cmbcountry.Width;

this.editcountry.Top = this.cmbcountry.Top;

this.editcity.Left = this.cmbcity.Left;

this.editcity.Width = this.cmbcity.Width;

this.editcity.Top = this.cmbcity.Top;

}

private void NavigationFP( bool bval)

{

this.ToolBarfirst.Enabled = bval;

this.ToolBarpreview.Enabled = bval;

}

private void NavigationNL( bool bval)

{

this.ToolBarnext.Enabled = bval;

this.ToolBarlast.Enabled = bval;

}

private void Enabled_AMS( bool bval)

{

this.ToolBaradd.Enabled = bval;

this.ToolBarmodify.Enabled = bval;

this.ToolBarsave.Enabled = !bval;

this.ToolBarcancel.Enabled = !bval;

this.lblNavLocation.Enabled = bval;

}

private void Enabled_CFP(bool bval)

{

//this.ToolBarcancel.Enabled = bval;

this.ToolBarsearch.Enabled = bval;

this.ToolBarprint.Enabled = bval;

}

 

//show photo

private void sub_showphoto()

{

if (mbaddflag == false)

{

if (this.editphoto_photo.Text.Trim() != "")

{

if (System.IO.File.Exists(this.editphoto_photo.Text.Trim()) == true)

{

this.Panel_photo.BorderStyle = BorderStyle.None;

this.Pic_photo.Image = Image.FromFile(this.editphoto_photo.Text.Trim());

this.Pic_photo.Left = (this.Panel_photo.Width - this.Pic_photo.Width) / 2;

this.Pic_photo.Top = (this.Panel_photo.Height - this.Pic_photo.Height) / 2;

this.Btnphoto_del.Enabled = false;

this.Btnphoto_new.Enabled = false;

if (mbeditflag == true)

{

this.Btnphoto_del.Enabled = true;

this.Btnphoto_new.Enabled = true;

}

}

else

{

//goto PP2;

this.Pic_photo.Image = null; //nothing();

this.Panel_photo.BorderStyle = BorderStyle.FixedSingle;

if (mbeditflag == true)

{

this.Btnphoto_new.Enabled = true;

}

else

{

this.Btnphoto_new.Enabled = false;

}

this.Btnphoto_del.Enabled = false;

return;

}

}

else

{

//PP2:

this.Pic_photo.Image = null; //nothing();

this.Panel_photo.BorderStyle = BorderStyle.FixedSingle;

if (mbeditflag == true)

{

this.Btnphoto_new.Enabled = true;

}

else

{

this.Btnphoto_new.Enabled = false;

}

this.Btnphoto_del.Enabled = false;

return;

}

}

}

private void NavPrev()

{

this.BindingContext[objbook_dset,"book"].Position = (this.BindingContext[objbook_dset,"book"].Position - 1);

this.objbook_dset_PositionChanged();

}

private void NavNext()

{

this.BindingContext[objbook_dset,"book"].Position = (this.BindingContext[objbook_dset,"book"].Position + 1);

this.objbook_dset_PositionChanged();

}

private void NavLast()

{

this.BindingContext[objbook_dset,"book"].Position = (this.objbook_dset.Tables["book"].Rows.Count - 1);

this.objbook_dset_PositionChanged();

}

//book_note Add event ... *****************************

private void sub_add()

{

this.cmbname.SelectedIndex = -1;

this.cmbfirst_name.SelectedIndex = -1;

this.cmbfather_name.SelectedIndex = -1;

this.cmbsex.SelectedIndex = -1;

this.cmbcivil_status.SelectedIndex = -1;

this.cmbcountry.SelectedIndex = -1;

this.cmbcity.SelectedIndex = -1;

try

{

// Clear out the current edits

this.BindingContext[objbook_dset,"book"].EndCurrentEdit();

this.BindingContext[objbook_dset,"book"].AddNew();

mbaddflag = true;

}

catch (System.Exception eEndEdit)

{

System.Windows.Forms.MessageBox.Show(eEndEdit.Message);

}

//show photo ...

this.Btnphoto_del.Enabled = false;

this.Btnphoto_new.Enabled = true;

this.objbook_dset_PositionChanged();

}

//show photo, add or remove/delete photo '''''''''''''''''''''

private void Btnphoto_new_Click(object sender, System.EventArgs e)

{

if ((mbaddflag == true) || (mbeditflag == true))

{

//OpenFileDialog control, displays the Photo corresponding and save it ...

sub_addphoto();

}

}

//OpenFileDialog control, displays the Photo corresponding and save it ...

private void sub_addphoto()

{

string vfilename;

this.OpenFileDialog1.Title = "Book note, Select Picture";

this.OpenFileDialog1.Filter = "All Files|*.*|JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";

this.OpenFileDialog1.FilterIndex = 3;

// Show the Dialog, if the user clicked in the dialog and a picture file was selected, open it.

if (OpenFileDialog1.ShowDialog() == DialogResult.OK)

{

//add record to table per_appphoto

vfilename = OpenFileDialog1.FileName;

this.Panel_photo.BorderStyle = BorderStyle.None;

this.Pic_photo.Image = Image.FromFile(OpenFileDialog1.FileName);

this.Pic_photo.Left = (this.Panel_photo.Width - this.Pic_photo.Width) / 2;

this.Pic_photo.Top = (this.Panel_photo.Height - this.Pic_photo.Height) / 2;

this.editphoto_photo.Text = vfilename;

this.Btnphoto_del.Enabled = true;

}

}

private void Btnphoto_del_Click(object sender, System.EventArgs e)

{

if(( mbaddflag == true) || (mbeditflag == true))

{

//remove/delete photo and clear the file photo name corresponding

sub_removephoto();

}

}

// remove/delete photo and clear the file photo name corresponding

private void sub_removephoto()

{

System.Windows.Forms.DialogResult response;

string msg_inf;

msg_inf = "are you sure want to remove the photo of - " + this.editfirst_name.Text + " " + this.editname.Text;

response = MessageBox.Show(msg_inf, work_VCnet.mainform.mainform_cl.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

//Gets the result of the MessageBox display.

if (response == DialogResult.Yes)

{

//clear photo ...

Panel_photo.BorderStyle = BorderStyle.FixedSingle;

Pic_photo.Image.Dispose();

Pic_photo.Image = null; //nothing;

editphoto_photo.Text = "";

Btnphoto_del.Enabled = false;

return;

}

if (response == DialogResult.No)

{

return;

}

}

//book_note Activated event ... *****************************

//book_note Activated event (responses from book_search form)

private void book_note_Activated(object sender, System.EventArgs e)

{

switch(work_VCnet.book_search.book_search_cl.findedit_Flag)

{

case "ok":

switch(book_note_cl.booknote_type)

{

case "find":

sub_findok();

break;

case "edit":

sub_modifyok();

break;

}

break;

case "cancel":

Searchedit_cancel();

break;

}

}

private void Searchedit_cancel()

{

mbeditflag = false;

objbook_dset_PositionChanged();

}

//book_note modify/edit event ... *****************************

private void sub_modify()

{

book_search fbook_search = new book_search();

book_note_cl.booknote_type = "edit";

mbeditflag = true;

sub_Searchedit();

fbook_search.Show();

}

private void sub_Searchedit()

{

NavigationFP(false);

NavigationNL(false);

Enabled_AMS(false);

Enabled_CFP(false);

this.ToolBarsave.Enabled = false;

this.ToolBarcancel.Enabled = false;

}

private void sub_modifyok()

{

this.BindingContext[objbook_dset,"book"].Position = work_VCnet.book_search.book_search_cl.book_recno;

this.objbook_dset_PositionChanged();

this.cmbname.Text = this.editname.Text;

this.cmbfirst_name.Text = this.editfirst_name.Text;

this.cmbfather_name.Text = this.editfather_name.Text;

this.DateTime_birth.Text = this.editbirth.Text;

this.cmbsex.Text = this.editsex.Text;

this.cmbcivil_status.Text = this.editcivil_status.Text;

this.cmbcountry.Text = this.editcountry.Text;

this.cmbcity.Text = this.editcity.Text;

}

private void Searchedit_cancel1()

{

mbeditflag = false;

objbook_dset_PositionChanged();

}

//book_note update/save event ... *****************************

private void sub_Update()

{

System.Windows.Forms.DialogResult response;

//convert, comboboxes to textboxes

this.editname.Text = this.cmbname.Text;

this.editfirst_name.Text = this.cmbfirst_name.Text;

this.editfather_name.Text = this.cmbfather_name.Text;

this.editbirth.Text = this.DateTime_birth.Text;

this.editsex.Text = this.cmbsex.Text;

this.editcivil_status.Text = this.cmbcivil_status.Text;

this.editcountry.Text = this.cmbcountry.Text;

this.editcity.Text = this.cmbcity.Text;

this.editoriginalfirst_name.Text = this.cmbfirst_name.Text;

this.editbirth_d.Text = System.Convert.ToString(this.DateTime_birth.Value.Day);

this.editbirth_m.Text = System.Convert.ToString(this.DateTime_birth.Value.Month);

this.editbirth_y.Text = System.Convert.ToString(this.DateTime_birth.Value.Year);

if (mbeditflag || mbaddflag)

{

if ((this.editname.Text == "") || (this.editfirst_name.Text == "") || (this.editfather_name.Text == ""))

{

response = MessageBox.Show("save operation aborted - name box, first name box or father name box empty(ies) ...", work_VCnet.mainform.mainform_cl.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (response == DialogResult.Yes)

return;

if (response == DialogResult.No)

sub_Cancel();

}

else

{

sub_updateok(this.editname.Text.Trim(), this.editfirst_name.Text.Trim(), this.editfather_name.Text.Trim());

try

{

// Attempt to update the datasource.

this.UpdateDataSet();

}

catch (System.Exception eUpdate)

{

// Display error message

System.Windows.Forms.MessageBox.Show(eUpdate.Message);

}

mbeditflag = false;

mbaddflag = false;

this.objbook_dset_PositionChanged();

}

}

}

//add data to comboboxes

private void sub_updateok(string v_name, string v_first, string v_father)

{

int v_ord;

vselect1 = new System.Data.OleDb.OleDbCommand("SELECT bookid, name, first_name, originalfirst_name, father_name FROM book WHERE ((name = '" + v_name + "') And (originalfirst_name = '" + v_first + "') And (father_name = '" + v_father + "')) ORDER BY bookid");

vda1 = new System.Data.OleDb.OleDbDataAdapter(vselect1);

vdset1 = new System.Data.DataSet();

vselect1.Connection = this.oleDbConnection1;

vdset1.EnforceConstraints = false;

try

{

this.oleDbConnection1.Open();

vda1.Fill(vdset1, "book");

}

catch (System.Exception fillException)

{

System.Windows.Forms.MessageBox.Show(fillException.Message);

}

vdset1.EnforceConstraints = true;

this.oleDbConnection1.Close();

if (vdset1.Tables["book"].Rows.Count > 0)

{

v_ord = (vdset1.Tables["book"].Rows.Count - 1);

this.editfirst_name.Text = this.editoriginalfirst_name.Text.Trim() + System.Convert.ToString(v_ord).Trim();

}

}

public void UpdateDataSet()

{

// Create a new dataset to hold the changes that have been made to the main dataset.

work_VCnet.book_dset objDataSetChanges = new work_VCnet.book_dset();

// Stop any current edits.

this.BindingContext[objbook_dset,"book"].EndCurrentEdit();

// Get the changes that have been made to the main dataset.

objDataSetChanges = ((work_VCnet.book_dset)(objbook_dset.GetChanges()));

// Check to see if any changes have been made.

if ((objDataSetChanges != null))

{

try

{

// There are changes that need to be made, so attempt to update the datasource by

// calling the update method and passing the dataset and any parameters.

this.UpdateDataSource(objDataSetChanges);

objbook_dset.Merge(objDataSetChanges);

objbook_dset.AcceptChanges();

}

catch (System.Exception eUpdate)

{

// Add your error handling code here.

throw eUpdate;

}

// Add your code to check the returned dataset for any errors that may have been

// pushed into the row object's error.

}

}

 

public void UpdateDataSource(work_VCnet.book_dset ChangedRows)

{

try

{

// The data source only needs to be updated if there are changes pending.

if ((ChangedRows != null))

{

// Open the connection.

this.oleDbConnection1.Open();

// Attempt to update the data source.

oleDbDataAdapter1.Update(ChangedRows);

}

}

catch (System.Exception updateException)

{

// Add your error handling code here.

throw updateException;

}

finally

{

// Close the connection whether or not the exception was thrown.

this.oleDbConnection1.Close();

}

}

//book_note Cancel event ... *****************************

private void sub_Cancel()

{

mbeditflag = false;

mbaddflag = false;

this.objbook_dset.RejectChanges();

this.BindingContext[objbook_dset,"book"].CancelCurrentEdit();

this.objbook_dset_PositionChanged();

}

//book_note find/search event ... *****************************

private void sub_find()

{

book_search fbook_search = new book_search();

book_note_cl.booknote_type = "find";

sub_Searchedit();

fbook_search.Show();

}

private void sub_findok()

{

this.BindingContext[objbook_dset,"book"].Position = work_VCnet.book_search.book_search_cl.book_recno;

this.objbook_dset_PositionChanged();

}

private void sub_print()

{

}



 

}

}

   
  
 



 

      Return