Подсистема автоматизированной тарификации биллинговой системы "Отик-интернет"

Основные типы тарифных планов российских Internet-провайдеров. Концепция баз данных. Схема информационных потоков. Структуры данных модуля учета тарифов. Методика испытаний и результаты экспериментальной проверки. Выбор средства и языка программирования.

Рубрика Программирование, компьютеры и кибернетика
Вид дипломная работа
Язык русский
Дата добавления 07.03.2012
Размер файла 1017,4 K

Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже

Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.

{

public String username ;

public String password ;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.TextBox tbUsername;

private System.Windows.Forms.TextBox tbPassword;

private System.ComponentModel.Container components = null;

public LoginForm()

{

InitializeComponent();

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.tbUsername = new System.Windows.Forms.TextBox();

this.tbPassword = new System.Windows.Forms.TextBox();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.SuspendLayout();

this.tbUsername.Location = new System.Drawing.Point(108, 20);

this.tbUsername.Name = "tbUsername";

this.tbUsername.Size = new System.Drawing.Size(152, 20);

this.tbUsername.TabIndex = 0;

this.tbUsername.Text = "";

this.tbPassword.Location = new System.Drawing.Point(108, 44);

this.tbPassword.Name = "tbPassword";

this.tbPassword.PasswordChar = '*';

this.tbPassword.Size = new System.Drawing.Size(152, 20);

this.tbPassword.TabIndex = 1;

this.tbPassword.Text = "";

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(16, 22);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(82, 16);

this.label1.TabIndex = 2;

this.label1.Text = "Пользователь:";

this.label2.AutoSize = true;

this.label2.Location = new System.Drawing.Point(50, 46);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(47, 16);

this.label2.TabIndex = 3;

this.label2.Text = "Пароль:";

this.button1.Location = new System.Drawing.Point(108, 76);

this.button1.Name = "button1";

this.button1.TabIndex = 4;

this.button1.Text = "Войти";

this.button1.Click += new System.EventHandler(this.button1_Click);

this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;

this.button2.Location = new System.Drawing.Point(186, 76);

this.button2.Name = "button2";

this.button2.TabIndex = 5;

this.button2.Text = "Отмена";

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.CancelButton = this.button2;

this.ClientSize = new System.Drawing.Size(266, 103);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Controls.Add(this.label2);

this.Controls.Add(this.label1);

this.Controls.Add(this.tbPassword);

this.Controls.Add(this.tbUsername);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "LoginForm";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "LoginForm";

this.ResumeLayout(false);

}

#endregion

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

{

username = this.tbUsername.Text ;

password = this.tbPassword.Text ;

this.DialogResult = System.Windows.Forms.DialogResult.OK ;

this.Close() ;

}

}

}

//=====================================================

// Основная форма работы с тарифами

//=====================================================

public MainForm(System.Data.Odbc.OdbcConnection cnt)

{

InitializeComponent();

TarifConnection = cnt ;

dpHeight = panelDescrTarif.Height ;

try

{

InitializeSQLDataBase() ;

BindDataToControls() ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

}

this.fmPayment = new PaymentForm(cnt) ;

this.fmHelp = new HelpForm() ;

this.fmTables = new ViewAllForm(cnt) ;

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

//

//работа с БД

//

private void InitializeSQLDataBase()

{

NameTarifTable = new System.Data.DataTable("name_tarif") ;

NameTarifTableAdapter = new System.Data.Odbc.OdbcDataAdapter("SELECT NameTarif, AbonPay FROM name_tarif", TarifConnection) ;

NameTarifCommandBuilder = new System.Data.Odbc.OdbcCommandBuilder(NameTarifTableAdapter) ;

NameTarifTableAdapter.Fill(NameTarifTable) ;

TimePaymentTable = new System.Data.DataTable("time_payment") ;

WeekEndPaymentTable = new System.Data.DataTable("weekend_payment") ;

dgNameTarif.DataSource = NameTarifTable ;

System.Windows.Forms.DataGridTableStyle ts = new System.Windows.Forms.DataGridTableStyle();

System.Windows.Forms.DataGridTextBoxColumn cs1 = new System.Windows.Forms.DataGridTextBoxColumn();

System.Windows.Forms.DataGridTextBoxColumn cs2 = new System.Windows.Forms.DataGridTextBoxColumn();

cs1.Width = 350 ;

cs1.HeaderText = "Название тарифа" ;

cs1.MappingName = "NameTarif" ;

cs2.HeaderText = "Абонентская плата" ;

cs2.Width = 150 ;

cs2.MappingName = "AbonPay" ;

ts.GridColumnStyles.Add(cs1) ;

ts.GridColumnStyles.Add(cs2) ;

ts.MappingName = "name_tarif" ;

dgNameTarif.TableStyles.Add(ts) ;

}

private void UpdateNameTarif()

{

NameTarifTable.Clear() ;

NameTarifTableAdapter.Fill(NameTarifTable) ;

dgNameTarif.Refresh() ;

BindDataToControls() ;

}

private void CalculateTraficSize()

{

int i = 0 ;

foreach(Object s in cbTraficType.Items)

{

if(cbTraficType.Text.Equals(s.ToString())) break ;

i += 10 ;

}

double scale = System.Math.Pow(2, i) ;

double size = System.Convert.ToDouble(tbTraficSize.Tag.ToString()) ;

tbTraficSize.Text = System.Convert.ToString( (System.UInt64)((size / scale))) ;

}

private void BindDataToControls()

{

try

{

String NameTarif = dgNameTarif[dgNameTarif.CurrentRowIndex, 0].ToString() ;

System.Data.Odbc.OdbcDataAdapter SelectTarif = new System.Data.Odbc.OdbcDataAdapter(

"SELECT * FROM name_tarif WHERE NameTarif='"+NameTarif+"'", TarifConnection) ;

System.Data.DataTable TarifTable = new System.Data.DataTable() ;

SelectTarif.Fill(TarifTable) ;

if( TarifTable.Rows.Count < 1 ) return ;

String IdSinglePayment = TarifTable.Rows[0]["IdSinglePayment"].ToString() ;

String IdTimePayment = TarifTable.Rows[0]["IdTimePayment"].ToString() ;

String IdWeekEndPayment = TarifTable.Rows[0]["IdWeekEndPayment"].ToString() ;

tbTraficSize.Tag = TarifTable.Rows[0]["FreeFavour"].ToString() ;

CalculateTraficSize() ;

System.Data.Odbc.OdbcDataAdapter SelectSinglePayment = new System.Data.Odbc.OdbcDataAdapter(

"SELECT WithEquipment, WithoutEquipment, MinPayment FROM single_payment WHERE IdSinglePayment="+IdSinglePayment, TarifConnection) ;

System.Data.Odbc.OdbcDataAdapter SelectTimePayment = new System.Data.Odbc.OdbcDataAdapter(

"SELECT TimeBegin, TimeEnd, Price, PriceOut FROM time_payment WHERE IdTimePayment="+IdTimePayment, TarifConnection) ;

System.Data.Odbc.OdbcDataAdapter SelectWeekEndPayment = new System.Data.Odbc.OdbcDataAdapter(

"SELECT TimeBegin, TimeEnd, Price, PriceOut FROM time_payment WHERE IdTimePayment="+IdWeekEndPayment, TarifConnection) ;

System.Data.DataTable SinglePaymentTable = new System.Data.DataTable() ;

SelectSinglePayment.Fill(SinglePaymentTable) ;

if( SinglePaymentTable.Rows.Count > 0 )

{

tbSPWithEquip.Text = SinglePaymentTable.Rows[0]["WithEquipment"].ToString() ;

tbSPWithoutEquip.Text = SinglePaymentTable.Rows[0]["WithoutEquipment"].ToString() ;

tbSPMinPayment.Text = SinglePaymentTable.Rows[0]["MinPayment"].ToString() ;

}

TimePaymentTable.Clear() ;

WeekEndPaymentTable.Clear() ;

SelectTimePayment.Fill(TimePaymentTable) ;

SelectWeekEndPayment.Fill(WeekEndPaymentTable) ;

dgTimePayment.DataSource = TimePaymentTable ;

dgWeekEndPayment.DataSource = WeekEndPaymentTable ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

}

}

[STAThread]

static void Main()

{

bool login = false ;

LoginForm fmLogin = new LoginForm() ;

System.Data.Odbc.OdbcConnection MySqlConnection = new System.Data.Odbc.OdbcConnection() ;

while(!login)

{

try

{

fmLogin.ShowDialog() ;

if ( fmLogin.DialogResult != System.Windows.Forms.DialogResult.OK ) return ;

String connectstr = "DRIVER={MySQL ODBC 3.51 Driver};"+

"SERVER=localhost;"+

"UID="+fmLogin.username+";"+

"PASSWORD="+fmLogin.password+";"+

"DATABASE=tarif";

MySqlConnection.ConnectionString = connectstr ;

MySqlConnection.Open() ;

login = true ;

}

catch(Exception ex)

{

MessageBox.Show("В доступе отказано") ;

}

}

Application.Run(new MainForm(MySqlConnection));

MySqlConnection.Close() ;

}

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

{

fmPayment.OpenedForChanging = false ;

fmPayment.NameTarif = dgNameTarif[dgNameTarif.CurrentRowIndex, 0].ToString() ;

fmPayment.ShowDialog(this) ;

UpdateNameTarif() ;

}

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

{

fmPayment.OpenedForChanging = true ;

fmPayment.NameTarif = dgNameTarif[dgNameTarif.CurrentRowIndex, 0].ToString() ;

fmPayment.ShowDialog(this) ;

UpdateNameTarif() ;

}

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

{

this.Close() ;

}

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

{

if( MessageBox.Show(this, "Подтверждаете удаление?", "Confirm",

System.Windows.Forms.MessageBoxButtons.YesNo,

System.Windows.Forms.MessageBoxIcon.Question) ==

System.Windows.Forms.DialogResult.Yes )

{

try

{

String NameTarif = dgNameTarif[dgNameTarif.CurrentRowIndex, 0].ToString() ;

System.Data.Odbc.OdbcCommand killCmd = new System.Data.Odbc.OdbcCommand(

"DELETE FROM name_tarif WHERE NameTarif='"+NameTarif+"'", TarifConnection) ;

killCmd.ExecuteNonQuery() ;

UpdateNameTarif() ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

}

}

}

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

{

fmHelp.ShowDialog() ;

}

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

{

UpdateNameTarif() ;

}

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

{

fmTables.ShowDialog() ;

}

private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs ce)

{

try

{

TarifConnection.Close() ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

}

}

private void dgNameTarif_CurrentCellChanged(object sender, EventArgs e)

{

BindDataToControls() ;

}

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

{

if(panelDescrTarif.Height == 0)

{

panelDescrTarif.Height = dpHeight ;

this.Height += dpHeight ;

}

else

{

panelDescrTarif.Height = 0 ;

this.Height -= dpHeight ;

}

this.panel1.Focus() ;

}

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

{

for ( int f=0 ; f<NameTarifTable.Rows.Count ; f++ )

{

if( dgNameTarif[f, 0].ToString().StartsWith(tbFind.Text) )

{

dgNameTarif.CurrentRowIndex = f ;

BindDataToControls() ;

break ;

}

}

}

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

{

CalculateTraficSize() ;

}

}

}

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

{

if(chbTimePayment.Checked)

{

tpOk = false ;

gbTimePayment.Enabled = true ;

}

else

{

gbTimePayment.Enabled = false ;

}

}

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

{

if(panelWeekEnd.Height == 0)

{

panelWeekEnd.Height = dpWEHeight ;

this.gbTimePayment.Height += dpWEHeight ;

this.Height += dpWEHeight ;

}

else

{

panelWeekEnd.Height = 0 ;

this.gbTimePayment.Height -= dpWEHeight ;

this.Height -= dpWEHeight ;

}

this.panel5.Focus() ;

}

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

{

if(panelBudni.Height == 0)

{

panelBudni.Height = dpBHeight ;

this.gbTimePayment.Height += dpBHeight ;

this.Height += dpBHeight ;

}

else

{

panelBudni.Height = 0 ;

this.gbTimePayment.Height -= dpBHeight ;

this.Height -= dpBHeight ;

}

this.panel5.Focus() ;

}

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

{

tpOk = false ;

wpOk = false ;

btReset.Enabled = OpenedForChanging ;

ClearForm() ;

if(OpenedForChanging)

{

System.Data.Odbc.OdbcDataAdapter SelectTarif = new System.Data.Odbc.OdbcDataAdapter(

"SELECT * FROM name_tarif WHERE NameTarif='"+NameTarif+"'", TarifConnection) ;

System.Data.DataTable TarifTable = new System.Data.DataTable() ;

SelectTarif.Fill(TarifTable) ;

if ( TarifTable.Rows.Count < 1 )

{

this.Close() ;

return ;

}

IdSinglePayment = (int)TarifTable.Rows[0]["IdSinglePayment"] ;

IdTimePayment = (int)TarifTable.Rows[0]["IdTimePayment"] ;

IdWeekEndPayment = (int)TarifTable.Rows[0]["IdWeekEndPayment"] ;

tbTraficSize.Tag = TarifTable.Rows[0]["FreeFavour"].ToString() ;

tbNameTarif.Text = TarifTable.Rows[0]["NameTarif"].ToString() ;

tbAbonPayment.Text = TarifTable.Rows[0]["AbonPay"].ToString() ;

tbTraficSize.Text = tbTraficSize.Tag.ToString() ;

cbTraficType.Text = "Байтах" ;

GetDataFromBase() ;

chbTimePayment.Checked = ( IdTimePayment != 0 ) ;

tpOk = CalculateTimePayment() ;

wpOk = CalculateWeekEndPayment() ;

}

}

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

{

GetDataFromBase() ;

}

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

{

ClearForm() ;

}

private void InsertData()

{

if ( chbTimePayment.Checked )

{

System.Data.Odbc.OdbcCommand maxTimePayment = new System.Data.Odbc.OdbcCommand(

"SELECT MAX(NumberTimePayment) FROM time_payment ", TarifConnection) ;

int max_tp = (int)maxTimePayment.ExecuteScalar() ;

foreach( System.Data.DataRow row in TimePaymentTable.Rows )

{

max_tp++ ;

string prIn = row[2].ToString().Replace(",", ".") ;

string prOut = row[3].ToString().Replace(",", ".") ;

System.TimeSpan ets = ((System.TimeSpan)row[1]) ;

string endtStr = System.Convert.ToString(ets.Days*24+ets.Hours)+":"+ets.Minutes+":"+ets.Hours ;

string req = "INSERT INTO time_payment (TimeBegin, TimeEnd, Price, PriceOut, IdTimePayment, NumberTimePayment, test) "+

"VALUES ('"+row[0].ToString()+"', '"+endtStr+"', "+prIn+", "+prOut+", "+

IdTimePayment+", "+max_tp+", 1)" ;

System.Data.Odbc.OdbcCommand addTimePayment = new System.Data.Odbc.OdbcCommand(

req, TarifConnection) ;

addTimePayment.ExecuteNonQuery() ;

}

if ( WeekEndPaymentTable.Rows.Count == 0 ) IdWeekEndPayment = 0 ;

if ( IdWeekEndPayment != 0 )

{

foreach( System.Data.DataRow row in WeekEndPaymentTable.Rows )

{

max_tp++ ;

string prIn = row[2].ToString().Replace(",", ".") ;

string prOut = row[3].ToString().Replace(",", ".") ;

System.TimeSpan ets = ((System.TimeSpan)row[1]) ;

string endtStr = System.Convert.ToString(ets.Days*24+ets.Hours)+":"+ets.Minutes+":"+ets.Hours ;

System.Data.Odbc.OdbcCommand addWeekEndPayment = new System.Data.Odbc.OdbcCommand(

"INSERT INTO time_payment (TimeBegin, TimeEnd, Price, PriceOut, IdTimePayment, NumberTimePayment, test) "+

"VALUES ('"+row[0].ToString()+"', '"+endtStr+"', "+prIn+", "+prOut+", "+

IdWeekEndPayment+", "+max_tp+", 1)", TarifConnection) ;

addWeekEndPayment.ExecuteNonQuery() ;

}

}

}

else

{

IdTimePayment = IdWeekEndPayment = 0 ;

}

System.Data.Odbc.OdbcCommand insertSinglePayment = new System.Data.Odbc.OdbcCommand(

"INSERT INTO single_payment (IdSinglePayment, WithEquipment, WithoutEquipment, MinPayment) "+

"VALUES ("+IdSinglePayment+", "+tbSPWithEquip.Text+", "+tbSPWithoutEquip.Text+

", "+tbSPMinPayment.Text+")", TarifConnection) ;

insertSinglePayment.ExecuteNonQuery() ;

System.Data.Odbc.OdbcCommand insertNameTarif = new System.Data.Odbc.OdbcCommand(

"INSERT INTO name_tarif (NameTarif, IdSinglePayment, IdTimePayment, IdWeekEndPayment, AbonPay, FreeFavour) "+

"VALUES ('"+tbNameTarif.Text+"', "+IdSinglePayment+", "+IdTimePayment+", "+IdWeekEndPayment+

", "+tbAbonPayment.Text+", "+tbTraficSize.Tag.ToString()+")", TarifConnection) ;

insertNameTarif.ExecuteNonQuery() ;

}

private void DeleteData()

{

System.Data.Odbc.OdbcCommand killNameTarif = new System.Data.Odbc.OdbcCommand(

"DELETE FROM name_tarif WHERE NameTarif='"+NameTarif+"'", TarifConnection) ;

killNameTarif.ExecuteNonQuery() ;

if ( IdSinglePayment != 0 )

{

System.Data.Odbc.OdbcCommand killSinglePayment = new System.Data.Odbc.OdbcCommand(

"DELETE FROM single_payment WHERE IdSinglePayment="+IdSinglePayment, TarifConnection) ;

killSinglePayment.ExecuteNonQuery() ;

}

if ( IdTimePayment != 0 )

{

System.Data.Odbc.OdbcCommand killTimePayment = new System.Data.Odbc.OdbcCommand(

"DELETE FROM time_payment WHERE IdTimePayment="+IdTimePayment, TarifConnection) ;

killTimePayment.ExecuteNonQuery() ;

}

if ( IdWeekEndPayment != 0 )

{

System.Data.Odbc.OdbcCommand killWeekEndPayment = new System.Data.Odbc.OdbcCommand(

"DELETE FROM time_payment WHERE IdTimePayment="+IdWeekEndPayment, TarifConnection) ;

killWeekEndPayment.ExecuteNonQuery() ;

}

}

private bool ValidateData()

{

tbAbonPayment.Text = tbAbonPayment.Text.Replace(",", ".") ;

tbSPWithEquip.Text = tbSPWithEquip.Text.Replace(",",".") ;

tbSPWithoutEquip.Text = tbSPWithoutEquip.Text.Replace(",",".") ;

tbSPMinPayment.Text = tbSPMinPayment.Text.Replace(",",".") ;

tbNameTarif.Text.Trim() ;

if ( tbNameTarif.Text == "" )

{

MessageBox.Show("Неврное имя тарифа!", "Ошибка",

System.Windows.Forms.MessageBoxButtons.OK,

System.Windows.Forms.MessageBoxIcon.Error) ;

return false ;

}

if ( (chbTimePayment.Checked) && (TimePaymentTable.Rows.Count == 0) )

{

MessageBox.Show("Введите временные платежи!", "Ошибка",

System.Windows.Forms.MessageBoxButtons.OK,

System.Windows.Forms.MessageBoxIcon.Error) ;

return false ;

}

if ( (chbTimePayment.Checked) && (!tpOk || !wpOk) )

{

MessageBox.Show("Проверте временные платежи!", "Ошибка",

System.Windows.Forms.MessageBoxButtons.OK,

System.Windows.Forms.MessageBoxIcon.Error) ;

return false ;

}

return true ;

}

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

{

if ( !ValidateData() ) return ;

if( MessageBox.Show(this, "Подтверждаете изменения?", "Confirm",

System.Windows.Forms.MessageBoxButtons.YesNo,

System.Windows.Forms.MessageBoxIcon.Question) ==

System.Windows.Forms.DialogResult.Yes )

{

bool success = false ;

if ( TarifConnection.State == System.Data.ConnectionState.Closed )

{

TarifConnection.Open() ;

}

try

{

CalculateTraficSize() ;

if ( OpenedForChanging )

{

DeleteData() ;

}

else

{

System.Data.Odbc.OdbcCommand maxIdSinglePayment = new System.Data.Odbc.OdbcCommand(

"SELECT MAX(IdSinglePayment) FROM single_payment ", TarifConnection) ;

IdSinglePayment = (int)maxIdSinglePayment.ExecuteScalar() + 1 ;

}

System.Data.Odbc.OdbcCommand maxIdTimePayment = new System.Data.Odbc.OdbcCommand(

"SELECT MAX(IdTimePayment) FROM time_payment ", TarifConnection) ;

int max_IdTP = (int)maxIdTimePayment.ExecuteScalar() ;

if ( IdTimePayment == 0 )

{

IdTimePayment = max_IdTP + 1 ;

if ( IdWeekEndPayment == 0 ) IdWeekEndPayment = max_IdTP + 2 ;

}

else

if ( IdWeekEndPayment == 0 ) IdWeekEndPayment = max_IdTP + 1 ;

InsertData() ;

success = true ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

}

if ( success ) this.Close() ;

}

}

private bool CalculateTimePayment()

{

if( !chbTimePayment.Checked ) return true;

if( TimePaymentTable.Rows.Count == 0 )

{

lbRestTimePayment.Text = "Введите данные!" ;

return false;

}

int f = 1 ;

for( ; f < TimePaymentTable.Rows.Count ; f++)

{

if( (dgTimePayment[f-1, 1].ToString() == "") || // == System.Convert.DBNul

(dgTimePayment[f, 0].ToString() == "") )

{

lbRestTimePayment.Text = "заполните строку " + (f+1) ;

return false;

}

System.TimeSpan odt = (System.TimeSpan)dgTimePayment[f-1, 1] ;

System.TimeSpan ndt = (System.TimeSpan)dgTimePayment[f, 0] ;

if( (ndt.Hours != odt.Hours+odt.Days*24) || (ndt.Minutes != odt.Minutes) )

{

lbRestTimePayment.Text = "ошибка в строке " + (f+1) ;

return false;

}

}

System.TimeSpan bdt = (System.TimeSpan)dgTimePayment[0, 0] ;

System.TimeSpan edt = (System.TimeSpan)dgTimePayment[f-1, 1] ;

edt = edt.Subtract(bdt) ;

System.TimeSpan rts = new System.TimeSpan(23, 59, 59) ;

rts = rts.Subtract(edt) ;

lbRestTimePayment.Text = rts.ToString() ; // rts.Hour + ":" + rts.Minute ;

return true ;

}

private bool CalculateWeekEndPayment()

{

if( !chbTimePayment.Checked ) return true ;

if( WeekEndPaymentTable.Rows.Count == 0 ) return true ;

int f = 1 ;

for( ; f < WeekEndPaymentTable.Rows.Count ; f++)

{

if( (dgWeekEndPayment[f-1, 1].ToString() == "") || // == System.Convert.DBNul

(dgWeekEndPayment[f, 0].ToString() == "") )

{

lbRestWeekEndPayment.Text = "заполните строку " + (f+1) ;

return false ;

}

System.TimeSpan odt = (System.TimeSpan)dgWeekEndPayment[f-1, 1] ;

System.TimeSpan ndt = (System.TimeSpan)dgWeekEndPayment[f, 0] ;

if( (ndt.Hours != odt.Hours+odt.Days*24) || (ndt.Minutes != odt.Minutes) )

{

lbRestWeekEndPayment.Text = "ошибка в строке " + (f+1) ;

return false ;

}

}

System.TimeSpan bdt = (System.TimeSpan)dgWeekEndPayment[0, 0] ;

System.TimeSpan edt = (System.TimeSpan)dgWeekEndPayment[f-1, 1] ;

edt = edt.Subtract(bdt) ;

System.TimeSpan rts = new System.TimeSpan(23, 59, 59) ;

rts = rts.Subtract(edt) ;

lbRestWeekEndPayment.Text = rts.ToString() ; // rts.Hour + ":" + rts.Minute ;

return true ;

}

private bool CheckTime(int bh, int bm, int eh, int em)

{

string errMsg = "" ;

if( (bh < 0) || (bh > 23) ) errMsg = "Некорректное начальное время! Введите часы в диапазоне от 0 до 23" ;

else if( (bm < 0) || (bm > 59) ) errMsg = "Некорректное начальное время! Введите минуты в диапазоне от 0 до 59" ;

else if( (eh < 0) || (eh > 24) ) errMsg = "Некорректное конечное время! Введите часы в диапазоне от 0 до 24" ;

else if( (em < 0) || (em > 59) ) errMsg = "Некорректное конечное время! Введите минуты в диапазоне от 0 до 59" ;

else if( eh < bh ) errMsg = "Начальное время должно быть меньше конечного!" ;

else if( (eh == bh) && (bm >= em) ) errMsg = "Начальное время должно быть меньше конечного!" ;

else if( (eh == 24) && (em > 0) ) errMsg = "Время должно быть в диапазоне от 00:00 до 24:00" ;

if( errMsg.Length != 0 )

{

MessageBox.Show(errMsg, "Ошибка",

System.Windows.Forms.MessageBoxButtons.OK,

System.Windows.Forms.MessageBoxIcon.Error) ;

return false ;

}

return true ;

}

private void dgTimePayment_CurrentCellChanged(object sender, EventArgs e)

{

ClearTimePayment();

int i = dgTimePayment.CurrentRowIndex;

if(dgTimePayment[i, 0] != System.Convert.DBNull)

{

System.TimeSpan bdt = (System.TimeSpan)dgTimePayment[i, 0] ;

tbBegHoursTP.Text = bdt.Hours.ToString() ;

tbBegMinutesTP.Text = bdt.Minutes.ToString() ;

}

if(dgTimePayment[i, 1] != System.Convert.DBNull)

{

System.TimeSpan edt = (System.TimeSpan)dgTimePayment[i, 1] ;

tbEndHoursTP.Text = System.Convert.ToString(edt.Hours + edt.Days*24) ;

tbEndMinutesTP.Text = edt.Minutes.ToString() ;

}

tbInTraficTP.Text = dgTimePayment[i, 2].ToString() ;

tbOutTraficTP.Text = dgTimePayment[i, 3].ToString() ;

}

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

{

System.Data.DataRow row = TimePaymentTable.NewRow() ;

TimePaymentTable.Rows.Add(row) ;

}

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

{

int bh, bm, eh, em ;

double intr, outr ;

tbInTraficTP.Text.Replace('.', ',') ;

tbOutTraficTP.Text.Replace('.', ',') ;

try

{

bh = System.Convert.ToInt32(tbBegHoursTP.Text) ;

bm = System.Convert.ToInt32(tbBegMinutesTP.Text) ;

eh = System.Convert.ToInt32(tbEndHoursTP.Text) ;

em = System.Convert.ToInt32(tbEndMinutesTP.Text) ;

intr = System.Convert.ToDouble(tbInTraficTP.Text) ;

outr = System.Convert.ToDouble(tbOutTraficTP.Text) ;

}

catch(Exception ex)

{

MessageBox.Show(ex.Message) ;

return ;

}

if( !CheckTime(bh, bm, eh, em) ) return ;

int i = dgTimePayment.CurrentRowIndex ;

System.TimeSpan bt = new TimeSpan(bh, bm, 1) ;

System.TimeSpan et = new TimeSpan(eh, em, 0) ;

dgTimePayment[i, 0] = bt ;

dgTimePayment[i, 1] = et ;

dgTimePayment[i, 2] = intr ;

dgTimePayment[i, 3] = outr ;

dgTimePayment.CurrentRowIndex = 0 ;

dgTimePayment.Invalidate() ;

NeedToCalculate = true ;

dgTimePayment.CurrentRowIndex = i ;

}

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

{

CurrencyManager currencyManager =

(CurrencyManager)BindingContext[dgTimePayment.DataSource, dgTimePayment.DataMember];

currencyManager.RemoveAt(currencyManager.Position);

ClearTimePayment() ;

}

private void dgWeekEndPayment_CurrentCellChanged(object sender, EventArgs e)

{

ClearWeekEndPayment();

int i = dgWeekEndPayment.CurrentRowIndex;

if(dgWeekEndPayment[i, 0] != System.Convert.DBNull)

{

System.TimeSpan bdt = (System.TimeSpan)dgWeekEndPayment[i, 0] ;

tbBegHoursWP.Text = bdt.Hours.ToString() ;

tbBegMinutesWP.Text = bdt.Minutes.ToString() ;

}

if(dgWeekEndPayment[i, 1] != System.Convert.DBNull)

{

System.TimeSpan edt = (System.TimeSpan)dgWeekEndPayment[i, 1] ;

tbEndHoursWP.Text = System.Convert.ToString(edt.Hours + edt.Days*24) ;

tbEndMinutesWP.Text = edt.Minutes.ToString() ;

}

tbInTraficWP.Text = dgWeekEndPayment[i, 2].ToString() ;

tbOutTraficWP.Text = dgWeekEndPayment[i, 3].ToString() ;

}

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

{

System.Data.DataRow row = WeekEndPaymentTable.NewRow() ;

WeekEndPaymentTable.Rows.Add(row) ;

}

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

{

int bh, bm, eh, em ;

double intr, outr ;

tbInTraficWP.Text.Replace('.', ',') ;

tbOutTraficWP.Text.Replace('.', ',') ;

try

{

bh = System.Convert.ToInt32(tbBegHoursWP.Text) ;

bm = System.Convert.ToInt32(tbBegMinutesWP.Text) ;

eh = System.Convert.ToInt32(tbEndHoursWP.Text) ;

em = System.Convert.ToInt32(tbEndMinutesWP.Text) ;

intr = System.Convert.ToDouble(tbInTraficWP.Text) ;

outr = System.Convert.ToDouble(tbOutTraficWP.Text) ;

}

catch(Exception ex)

{

MessageBox.Show(ex.Message) ;

return ;

}

if ( !CheckTime(bh, bm, eh, em) ) return ;

int i = dgWeekEndPayment.CurrentRowIndex ;

System.TimeSpan bt = new TimeSpan(bh, bm, 1) ;

System.TimeSpan et = new TimeSpan(eh, em, 0) ;

dgWeekEndPayment[i, 0] = bt ;

dgWeekEndPayment[i, 1] = et ;

dgWeekEndPayment[i, 2] = intr ;

dgWeekEndPayment[i, 3] = outr ;

dgWeekEndPayment.CurrentRowIndex = 0 ;

dgWeekEndPayment.Invalidate() ;

NeedToCalculate = true ;

dgWeekEndPayment.CurrentRowIndex = i ;

}

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

{

CurrencyManager currencyManager =

(CurrencyManager)BindingContext[dgWeekEndPayment.DataSource, dgWeekEndPayment.DataMember];

currencyManager.RemoveAt(currencyManager.Position);

ClearWeekEndPayment() ;

}

private void dgTimePayment_Paint(object sender, PaintEventArgs e)

{

if( NeedToCalculate )

{

tpOk = CalculateTimePayment() ;

NeedToCalculate = false ;

}

}

private void dgWeekEndPayment_Paint(object sender, PaintEventArgs e)

{

if( NeedToCalculate )

{

wpOk = CalculateWeekEndPayment() ;

NeedToCalculate = false ;

}

}

}

}

//=====================================================

// Просмотр всех таблиц, входящих в базу

//=====================================================

public ViewAllForm(System.Data.Odbc.OdbcConnection cnt)

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

TarifConnection = cnt ;

try

{

TarifDataSet = new System.Data.DataSet() ;

InitializeMySql() ;

}

catch (Exception ex)

{

MessageBox.Show(ex.Message) ;

} ;

}

private void InitializeMySql()

{

/* Подключение к базе данных

String connectstr = "DRIVER={MySQL ODBC 3.51 Driver};"+

"SERVER=localhost;"+

// "UID=;"+

// "PASSWORD=;"+

"DATABASE=tarif";

TarifConnection = new System.Data.Odbc.OdbcConnection(connectstr) ;

TarifConnection.Open() ;

*/

TarifDataSet.Clear() ;

NameTarifTableAdapter = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM name_tarif", TarifConnection) ;

SinglePaymentTableAdapter = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM single_payment", TarifConnection) ;

TimePaymentTableAdapter = new System.Data.Odbc.OdbcDataAdapter("SELECT * FROM time_payment", TarifConnection) ;

/*

NameTarifCommandBuilder = new System.Data.Odbc.OdbcCommandBuilder(NameTarifTableAdapter) ;

SinglePaymentCommandBuilder = new System.Data.Odbc.OdbcCommandBuilder(SinglePaymentTableAdapter) ;

TimePaymentCommandBuilder = new System.Data.Odbc.OdbcCommandBuilder(TimePaymentTableAdapter) ;

*/

NameTarifTableAdapter.Fill(TarifDataSet, "name_tarif") ;

SinglePaymentTableAdapter.Fill(TarifDataSet, "single_payment") ;

TimePaymentTableAdapter.Fill(TarifDataSet, "time_payment") ;

dgNameTarif.SetDataBinding(TarifDataSet, "name_tarif") ;

dgSinglePayment.SetDataBinding(TarifDataSet, "single_payment") ;

dgTimePayment.SetDataBinding(TarifDataSet, "time_payment") ;

}

Размещено на Allbest.ru


Подобные документы

Работы в архивах красиво оформлены согласно требованиям ВУЗов и содержат рисунки, диаграммы, формулы и т.д.
PPT, PPTX и PDF-файлы представлены только в архивах.
Рекомендуем скачать работу.