private void but_Login_Click(object sender, EventArgs e) { try { but_Login.Enabled = false; Msg.RunInBackground( delegate(object obj, DoWorkEventArgs ce) { if (TB_name.Text.Trim() == "") { string msg = "用户名不能为空"; errorProvider1.SetError(TB_name, msg); Msg.ShowErrorMsg(msg); TB_name.Focus(); return; } else if (TB_Pwd.Text.Trim() == "") { string msg = "密码不能为空"; errorProvider1.SetError(TB_Pwd, msg); Msg.ShowErrorMsg(msg); TB_Pwd.Focus(); return; } ClientServicesProxy proxys = new ClientServicesProxy(); tb_User p = new tb_User { User_Name = TB_name.Text.Trim(), User_Pwd = TB_Pwd.Text.Trim() }; ce.Result = proxys.Find(p).FirstOrDefault(); }, delegate(object obj, RunWorkerCompletedEventArgs rce) { var result = rce.Result as tb_User; if (result.IsNotNull() && result.User_Name.IsNotNull() && result.User_Pwd.IsNotNull() && result.User_Name.IsEquals(TB_name.Text.Trim()) && result.User_Pwd.IsEquals(TB_Pwd.Text.Trim())) { App.CertificationUser = result; Frm_Main main = new Frm_Main(); Frm_SDXT.pass = TB_Pwd.Text.Trim(); main.Show(); this.Hide(); } else { string msg = "用户名或密码错误"; errorProvider1.SetError(TB_Pwd, msg); Msg.ShowErrorMsg(msg); TB_Pwd.Focus(); TB_name.Focus(); } }); } catch (Exception ex) { Msg.ShowErrorMsg(ex); } finally { but_Login.Enabled = true; } }
/// <summary> /// Adds Items to the bill /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_addToBill_Click(object sender, EventArgs e) { if (validation()) { if (billArea.Controls.Count < 1) { RefreshBill(); } billItem bItem = new billItem(); bItem.ItemName = TB_name.Text; bItem.ItemCat = cat; bItem.ItemPrice = TB_price.Text; bItem.ItemQty = TB_qty.Text; bItem.Size = new Size(245, 45); bItem.DoubleClick += BItem_DoubleClick; billArea.Controls.Add(bItem); this.ActiveControl = bItem; billArea.ScrollControlIntoView(bItem); //Add item to the bill try { String Qry = "INSERT INTO Bill (Bill_ID, ItemID , ItemName, ItemCategory, ItemDiscount, ItemPrice, Qty, Total, Date, Time) " + "VALUES (" + BillID + "," + itemID + "," + "'" + TB_name.Text + "'," + "'" + cat + "'," + TB_dis.Text + "," + TB_price.Text + "," + TB_qty.Text + "," + float.Parse(TB_qty.Text) * float.Parse(TB_price.Text) + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "'" + ",'" + DateTime.Now.ToString("hh:mm:ss") + "')"; SqlCommand cmd = new SqlCommand(Qry, Connection); Connection.Open(); cmd.ExecuteNonQuery(); itemID = 0; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Connection.Close(); } CalculateTotal(); ReportAnalysis analysis = new ReportAnalysis(); analysis.UpdatePopularity(); TB_dis.Clear(); TB_name.Clear(); TB_price.Clear(); TB_qty.Clear(); MaskAdd(TB_name, "Enter Item Name"); MaskAdd(TB_price, "Enter Item Price"); MaskAdd(TB_qty, "Qty"); MaskAdd(TB_dis, "Discount"); MaskAdd(TB_search, "Search Items"); } }