private void btnAddUser_Click(object sender, EventArgs e) { try { if (!dxErrorProvider1.HasErrors) { int userId = Convert.ToInt32(cmbUserName.EditValue); int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; string password = txtPassword.EditValue.ToString().ToLower(); var ValidUser = db.Users.Where(s => s.ID == userId && s.Password.ToLower() == password).SingleOrDefault(); var _shift = db.Shifts.Where(s => s.ID == ModuleClass.shiftID).SingleOrDefault(); if (ValidUser != null) { if (_shift.ShiftUsers.Where(s => s.UserID == userId).Any()) { MessageBox.Show(" للوردية " + cmbUserName.Text + " لا يمكن إضافة المسخدم ", "المستخدم موجود بالوردية"); return; } DataAccess.ShiftUser shiftUser = db.ShiftUsers.Create(); shiftUser.ShiftID = _shift.ID; shiftUser.UserID = userId; shiftUser.LogInTime = DateTime.Now; shiftUser.LogoutTime = DateTime.Now; shiftUser.Duration = 0; shiftUser.Flag = 0; _shift.ShiftUsers.Add(shiftUser); if (db.SaveChanges() > 0) { var message = "" + UserData.Default.BranchName + " فرع " + " للوردية " + cmbUserName.Text + " تمت إضافة المستخدم "; PushMessage.SendSignOnMessage(message); MessageBox.Show(message); Thread.Sleep(1500); this.Close(); } } else { MessageBox.Show("الرجاء التأكد من اسم المستخدم وكلمة المرور"); } } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); db = ModuleClass.GetConnection(); } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { try { if (e.Column != colCurrentQuanity) { return; } string cellValue = e.Value.ToString();// +" " + gridView1.GetRowCellValue(e.RowHandle, gridView1.Columns["CurrentQuanity"]).ToString(); var row = gridView1.GetFocusedRow() as DataAccess.Inventory; GridView view = (GridView)sender; var editor = view.ActiveEditor; OldQTY = Convert.ToInt32(view.ActiveEditor.OldEditValue); NewQTY = Convert.ToInt32(view.ActiveEditor.EditValue); ItemName = gridView1.GetRowCellDisplayText(view.FocusedRowHandle, colItemID).ToString(); row.SystemQTY = OldQTY; row.ActualQTY = NewQTY; row.InventoryDate = DateTime.Now; if (cbAutoSave.Checked) { if (db.SaveChanges() > 0) { string message = ""; message += " تم تغير كمية الصنف: " + ItemName + " من " + OldQTY + " الي " + NewQTY + Environment.NewLine; message += "الموظف" + UserData.Default.UserName + Environment.NewLine; message += "@ Reda" + UserData.Default.BranchID + Environment.NewLine; gridControl1.DataSource = null; this.inventoryBindingSource.DataSource = null; txtSearch.Focus(); txtSearch.SelectAll(); this.Text = ItemName + " " + NewQTY; PushMessage.SendDirectInventory(message); } } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); } }
private void btnAddUser_Click(object sender, EventArgs e) { try { if (!dxErrorProvider1.HasErrors) { DataAccess.Request request = db.Requests.Create(); itemID = 0; userID = Convert.ToInt32(UserData.Default.UserID); string UserName = Convert.ToString(UserData.Default.UserName); branchID = Convert.ToInt32(UserData.Default.BranchID); quantity = Convert.ToInt32(txtQuantity.EditValue); string desciption = txtDescription.Text; request.UserID = userID; request.BranchID = branchID; request.RequestDate = DateTime.Now; request.Quantity = quantity; request.Description = desciption; var itemObj = (ItemObject)listBoxControl1.SelectedItem; request.ItemID = Convert.ToInt32(itemObj.Data); db.Requests.Add(request); if (db.SaveChanges() > 0) { #if !DEBUG var message = "" + UserData.Default.BranchName + " فرع " + UserName + " من المستخدم " + lblItem.Text + " تمت طلب الصنف "; PushMessage.SendDirectMessage(message); #endif MessageBox.Show("تم حفظ الطلب و إرساله للإدارة", "شكرا لاهتمامك"); // Thread.Sleep(1500); // this.Close(); } else { MessageBox.Show("توجد مشكلة في حفظ البيانات، الرجاء المحاولة مرة أخري"); } } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); db = ModuleClass.GetConnection(); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (db.SaveChanges() > 0) { string message = ""; message += "تم تغير كمية الصنف:" + ItemName + "من" + OldQTY + "الي" + NewQTY + Environment.NewLine; message += "الموظف" + UserData.Default.UserName + Environment.NewLine; message += "@ Reda" + UserData.Default.BranchID + Environment.NewLine; gridControl1.DataSource = null; this.inventoryBindingSource.DataSource = null; txtSearch.Focus(); PushMessage.SendDirectInventory(message); } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); } }
bool SendDevicesStatus() { string message = ""; bool status = true; if (!tsColorPrinter.IsOn) { message += tsColorPrinter.Properties.OffText + "\n"; status = false; } if (!tsFax.IsOn) { message += tsFax.Properties.OffText + "\n"; status = false; } if (!tsLaserPrinter.IsOn) { message += tsLaserPrinter.Properties.OffText + "\n"; status = false; } if (!tsPackingMachine.IsOn) { message += tsPackingMachine.Properties.OffText + "\n"; status = false; } if (!tsPhotocopier.IsOn) { message += tsPhotocopier.Properties.OffText + "\n"; status = false; } if (!tsScanner.IsOn) { message += tsScanner.Properties.OffText + "\n"; status = false; } if (!status) { try { PushMessage.SendDevicesStatusMessage(UserData.Default.UserName + Environment.NewLine + " @ Reda" + UserData.Default.BranchID + Environment.NewLine + message); ////Thread thread = new Thread(() => PushMessage.SendDevicesStatusMessage(UserData.Default.UserName + Environment.NewLine + " @ Reda" + UserData.Default.BranchID + Environment.NewLine + message)); ////thread.Start(); } catch (Exception ex) { //Do nothing } return(true); } else { message = "جميع الأجهزة تعمل بصورة جيدة"; try { Thread thread = new Thread(() => PushMessage.SendDevicesStatusMessage(UserData.Default.UserName + " @ Reda" + UserData.Default.BranchID + Environment.NewLine + message)); thread.Start(); } catch (Exception ex) { //Do nothing } return(true); } }
private void btnShiftClose_Click(object sender, EventArgs e) { try { int userId = Convert.ToInt32(UserData.Default.UserID);//Convert.ToInt32(cmbUsersRPT.EditValue); DateTime currentDate = DateTime.Now; if (isValid() && MessageBox.Show("هل أنت متأكد من صحة بيانات الوردية و حالة جميع الأجهزة؟", "الرجاء التأكد من البيانات قبل قفل الوردية", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { //Close shift for logged in users in shift var shiftUsers = db.ShiftUsers.Where(s => s.ShiftID == _shift.ID && s.Flag == 0); foreach (DataAccess.ShiftUser shiftUser in shiftUsers) { shiftUser.LogoutTime = DateTime.Now; TimeSpan dur = shiftUser.LogoutTime.Subtract(shiftUser.LogInTime); shiftUser.Duration = Convert.ToDecimal(Math.Round(dur.TotalMinutes, 2)); // shiftUser.Duration =Math.Round(Decimal.Parse(dur.TotalMinutes.ToString()), 2); shiftUser.Flag = 1; } _shift.LogoutTime = DateTime.Now; _shift.Flag = 1; if (db.SaveChanges() > 0) { if (!SendDevicesStatus()) { MessageBox.Show("لم يستطع النظام ارسال حالة الأجهزة عن طريق رسائل الموبايل \nالرجاء تبليغ الإدارة بواسطة التلفون"); } //Send To Whatsapp try { // +"," + ExpenseToUser.MobileNo + "," + insertedUser.MobileNo; string message = "-------------------" + Environment.NewLine; message += " وردية الفرع " + _shift.Branch.BranchName + Environment.NewLine; message += " الموظف " + _shift.User.FullName + Environment.NewLine; message += " زمن الدخول " + _shift.LoginTime + Environment.NewLine; message += " زمن الخروج " + _shift.LogoutTime + Environment.NewLine; message += " الفكة بداية الوردية" + txtCoinsAmountStart.EditValue + Environment.NewLine; message += " الفكة نهاية الوردية" + txtCoinsAmountClose.EditValue + Environment.NewLine; message += " الكاش بداية الوردية" + txtCashAmountStart.EditValue + Environment.NewLine; message += " الكاش نهاية الوردية " + txtCashAmountClose.EditValue + Environment.NewLine; message += " رصيد الكهرباء الأولي " + _shift.ElectricityAmountStart + Environment.NewLine; message += " رصيد الكهرباء المتبقي " + _shift.ElectricityAmountClose + Environment.NewLine; message += " عدد فواتير الكهرباء " + txtNoOfElectricityInvoice.EditValue + Environment.NewLine; message += " مجموع مبيعات الكهرباء " + txtElectricityAmountNet.EditValue + Environment.NewLine; message += " مجموع فواتير البيع " + txtSaleTotal.EditValue + Environment.NewLine; message += " مجموع التخفيض " + txtDiscountTotal.EditValue + Environment.NewLine; message += " مجموع المنصرفات " + txtExpensesTotal.EditValue + Environment.NewLine; message += " صافي المبلغ - النظام " + txtSystemCash.EditValue + Environment.NewLine; message += " المبلغ المتوفر - الموظف " + txtUserCash.EditValue + Environment.NewLine; message += " الفرق " + txtDifrrent.EditValue + Environment.NewLine; message += "-----المنصرفات----- " + Environment.NewLine; var shift_Expendses = db.vw_Expense.Where(s => s.InsertedUserId == userId && s.Date.Year == currentDate.Year && s.Date.Month == currentDate.Month && s.Date.Day == currentDate.Day); foreach (var expense in shift_Expendses) { message += expense.Description + " " + expense.Amount + " " + expense.UserName; message += Environment.NewLine; } message += "-------------------"; var insertedUser = db.Users.Where(s => s.ID == userId).SingleOrDefault(); PushMessage.SendShiftCloseMessage(insertedUser, message); Thread.Sleep(1500); var list2 = db.vw_ShiftUser.Where(s => s.ShiftID == _shift.ID /*&& s.Flag == 0*/).ToList(); string UserStatusMessage = " الوضع المالي للموظفين بالوردية" + Environment.NewLine; List <string> userIDs = new List <string>(); foreach (var su in list2) { userIDs.Add(su.PushoverID); var userPayment = db.UserPayments.Where(s => s.UserID == su.UserID).OrderByDescending(s => s.ID).Take(1).SingleOrDefault(); var amount = userPayment.Amount; var balance = userPayment.Balance; UserStatusMessage += su.FullName + Environment.NewLine + " " + " أجرة الوردية: " + amount + Environment.NewLine + " " + " المطالبة الحالية: " + balance + Environment.NewLine; } PushMessage.SendUserPaymentStatusMessage(UserStatusMessage, userIDs); Thread.Sleep(1500); PushMessage.SendDailyInventoryStatus(branchID, _shift.LoginTime, _shift.LogoutTime); Thread.Sleep(1500); PushMessage.SendItemWithoutBarcode(branchID, _shift.LoginTime, _shift.LogoutTime); } catch (Exception ex) { //Do nothing } ExportUSerPaymentReport(); ExportShiftReport(); MessageBox.Show("تم حفظ تقرير الوردية والتقرير المالي للموظف بسطح المكتب", "تم قفل الورديه بنجاح، "); ////ShiftRPT rpt = new ShiftRPT(); ////int userId = Convert.ToInt32(UserData.Default.UserID); ////var list = db.Shifts.Where(s => s.ID == _shift.ID);//.SingleOrDefault(); ////if (list != null) ////{ //// rpt.RequestParameters = false; //// rpt.parameterBranchName.Value = db.Branches.Where(s => s.ID == branchID).SingleOrDefault().BranchName; //// rpt.parameterUserName.Value = db.Users.Where(s => s.ID == userId).SingleOrDefault().UserName; //// rpt.DataSource = list.ToList(); //// //rpt.parameterBranchName.Value = UserData.Default.BranchID; //// //rpt.parameterDate.Value = cmbDate.DateTime; //// //rpt.parameterInsertedUser.Value = UserData.Default.UserName; //// try //// { //// ReportPrintTool tool = new ReportPrintTool(rpt); //// tool.ShowPreview(); //// } //// catch (Exception ex) //// { //// ModuleClass.ShowMessage(this, ex, "خطأ", null); //// } ////} ////else ////{ //// MessageBox.Show("لا توجد ورديه في هذا التاريخ"); ////} this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } } else { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (isValid()) { int userID = _expense.UserID; string toUser = cmbExpensesTo.Text; DateTime from = new DateTime(_expense.Date.Year, _expense.Date.Month, _expense.Date.Day, 0, 0, 0); DateTime to = new DateTime(_expense.Date.Year, _expense.Date.Month, _expense.Date.Day, 23, 59, 59); int MaxExpensePerDay = Convert.ToInt32(db.Users.Where(s => s.ID == userID).SingleOrDefault().MaxExpensePerDay); var todayExpensePerDay = db.vw_Expense.Where(s => s.UserID == userID && (s.Date >= from && s.Date <= to)).DefaultIfEmpty().Sum(s => (decimal?)s.Amount ?? 0); if ((todayExpensePerDay + _expense.Amount) > MaxExpensePerDay) { MessageBox.Show("أقصي مبلغ يمكن صرفه ل " + toUser + " خلال اليوم هو " + MaxExpensePerDay + Environment.NewLine + " المنصرف اليومي حتي الآن " + todayExpensePerDay, "لا يمكن صرف المبلغ", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } int MaxExpensePerMonth = Convert.ToInt32(db.Users.Where(s => s.ID == userID).SingleOrDefault().MaxExpensePerMonth); from = new DateTime(_expense.Date.Year, _expense.Date.Month, 1, 0, 0, 0); to = new DateTime(_expense.Date.Year, _expense.Date.Month, DateTime.DaysInMonth(_expense.Date.Year, _expense.Date.Month), 23, 59, 59); var todayExpensePerMonth = db.vw_Expense.Where(s => s.UserID == userID && (s.Date >= from && s.Date <= to)).DefaultIfEmpty().Sum(s => (decimal?)s.Amount ?? 0); if ((todayExpensePerMonth + _expense.Amount) > MaxExpensePerMonth) { MessageBox.Show("أقصي مبلغ يمكن صرفه ل " + toUser + " خلال الشهر هو " + MaxExpensePerMonth + Environment.NewLine + " المنصرف الشهري حتي الآن " + todayExpensePerMonth, "لا يمكن صرف المبلغ", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (_expense.ShiftID == 0) { ////MessageBox.Show("لا يمكن حفظ البيانات، الرجاء مراجعة مسؤول النظام"); ////return; _expense.ShiftID = 30; } db.Expenses.Add(_expense); if (db.SaveChanges() > 0) { //Send To Whatsapp try { var ExpenseToUser = cmbExpensesTo.GetSelectedDataRow() as DataAccess.User; int userId = Convert.ToInt32(UserData.Default.UserID); var insertedUser = db.Users.Where(s => s.ID == userId).SingleOrDefault(); var usersMobileNos = db.Users.Where(s => s.IsEnable == true && s.IsAdmin == true).Select(s => s.MobileNo).ToList(); string recervers = ""; //foreach (var item in usersMobileNos) //{ // recervers += (item + ","); //} string message = "تم صرف مبلغ " + _expense.Amount + " لصالح " + ExpenseToUser.FullName + " عبارة عن " + _expense.Description + " تم الإدخال بواسطة " + insertedUser.FullName; var userPayment = db.UserPayments.Where(s => s.UserID == _expense.UserID).OrderByDescending(s => s.ID).Take(1).SingleOrDefault(); var amount = userPayment.Amount; var balance = userPayment.Balance; message += Environment.NewLine + " " + " آخر منصرف: " + amount + Environment.NewLine + " " + " المطالبة الحالية: " + balance + Environment.NewLine; Thread thread = new Thread(() => PushMessage.SendDialyExpense(insertedUser, ExpenseToUser, message)); thread.Start(); //send by Email //string EmailReceivers = emails;// UserData.Default.EmailReceivers; //Thread emailThread = new Thread(() => ModuleClass.SendEmail("", "منصرف", message)); //emailThread.Start(); MessageBox.Show(message, "تم حفظ المنصرف"); this.Close(); } catch (Exception ex) { //Do nothing } // MessageBox.Show("تم الحفظ"); this.Close(); _expense = db.Expenses.Create(); _expense.Date = DateTime.Now; _expense.InsertedUserId = Convert.ToInt32(UserData.Default.UserID); _expense.BranchID = Convert.ToInt32(UserData.Default.BranchID); bindingSourceExpense.DataSource = _expense; } } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); } }
private void btnNumberOfhoursToUser_Click(object sender, EventArgs e) { try { dxErrorProvider1.ClearErrors(); if (cmbUserName.EditValue == null) { dxErrorProvider1.SetError(cmbUserName, "يجد تحديد الموظف "); } if (txtHourNumbers.EditValue == "") { dxErrorProvider1.SetError(txtHourNumbers, "يجد تحديد عدد الساعات للموظف"); } if (txtDescription.Text == string.Empty || txtDescription.Text == "" || txtDescription.Text == null || txtDescription.Text.Length < 7) { dxErrorProvider1.SetError(txtDescription, "يجد تحديد الغرض بصورة واضحة"); } if (!dxErrorProvider1.HasErrors) { int userId = Convert.ToInt32(cmbUserName.EditValue); int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; var message = " تمت إضافة زمن للمستخدم " + cmbUserName.Text + " لمدة " + txtHourNumbers.Text + " ساعات "; message += " الغرض "; message += txtDescription.Text; string NumberOfhours = txtHourNumbers.EditValue.ToString().ToLower(); decimal balance = db.UserPayments.Where(s => s.UserID == userId).Select(s => (decimal?)s.Amount).Sum() ?? 0; //(SELECT SUM(Amount) FROM[dbo].[UserPayment] Where UserID = @UserID) decimal hourRate = Convert.ToDecimal(cmbUserName.GetColumnValue("HourRate")); var _userPayment = new DataAccess.UserPayment(); _userPayment.Amount = Convert.ToDecimal(NumberOfhours) * hourRate; _userPayment.Balance = balance + _userPayment.Amount; _userPayment.Date = DateTime.Now; _userPayment.Desciption = message; _userPayment.InvoiceID = 0; _userPayment.PaymentType = 1; _userPayment.UserID = userId; db.UserPayments.Add(_userPayment); /* * var _shift = db.Shifts.Where(s => s.BranchID == 1).OrderBy(s => s.ID).First();// .LastOrDefault();//.SingleOrDefault(); * DataAccess.ShiftUser newShift = new DataAccess.ShiftUser(); * newShift.Duration = Convert.ToDecimal(NumberOfhours) * 60; * newShift.ShiftID = _shift.ID; * newShift.LogInTime = DateTime.Now.AddHours(-1 * Convert.ToDouble(NumberOfhours)); * newShift.LogoutTime = DateTime.Now; * newShift.UserID = userId; * newShift.Flag = 1; * db.ShiftUsers.Add(newShift); */ if (db.SaveChanges() > 0) { if (cmbUserName.GetColumnValue("PushoverID") != null) { string pushid = cmbUserName.GetColumnValue("PushoverID").ToString(); List <string> userIDs = new List <string>(); userIDs.Add(pushid); var userPayment = db.UserPayments.Where(s => s.UserID == userId).OrderByDescending(s => s.ID).Take(1).SingleOrDefault(); var amount = userPayment.Amount; balance = userPayment.Balance; message += Environment.NewLine + " " + "القيمة " + amount + Environment.NewLine + " " + " المطالبة الحالية: " + balance + Environment.NewLine; PushMessage.SendUserPaymentStatusMessage(message, userIDs); MessageBox.Show(message); Thread.Sleep(1500); } this.Close(); } } } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); db = ModuleClass.GetConnection(); } }
void SaveItem(bool closeWindow) { try { if (CustomValidateForm()) { if (isNew) { var catId = Convert.ToInt32(cmbCategory.GetColumnValue("ID")); var code = cmbCategory.GetColumnValue("code").ToString(); int count = db.Items.Where(s => s.CategoryID == catId).Count(); string BarcodeText = "7" + code /*+ "-"*/ + (count + 1).ToString("000"); item.BarcodeText = BarcodeText; item.Symbology = "Code128"; isNew = false; DataAccess.ItemBarcode ibc = new DataAccess.ItemBarcode(); ibc.ItemID = item.ID; ibc.BarcodeText = BarcodeText; ibc.SystemBarcode = true; db.ItemBarcodes.Add(ibc); } //this.item.SalePrice = 20; //var res = db.ChangeTracker.Entries(); //if (res.Any()) //{ //} if (db.SaveChanges() > 0) { //use to send notificationn when change price if (oldPrice != null && oldPrice != item.SalePrice) { //Send notification message string message = "تم تغيير سعر الصنف " + item.Name + " من " + oldPrice + " الي " + item.SalePrice; PushMessage.SendPriceChangeMessage(message); DataAccess.MarqueeMessage marqueeMessage; int LifetimeDays = 3; foreach (var branch in db.Branches.ToList()) { marqueeMessage = new DataAccess.MarqueeMessage { BranchID = branch.ID, LifetimeDays = LifetimeDays, Message = message, Date = DateTime.Now.AddDays(LifetimeDays), UserID = Convert.ToInt32(UserData.Default.UserID) }; db.MarqueeMessages.Add(marqueeMessage); } if (db.SaveChanges() > 0) { } } valid = true; if (closeWindow) { this.Close(); } } } } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) { ModuleClass.ShowExceptionMessage(this, ex, "رقم الباركود قد يكون تم إدخاله لصنف آخر", null); bindingSourceItemBarcode.DataSource = /*this.item.ItemBarcodes;*/ db.ItemBarcodes.Where(s => s.ItemID == item.ID).ToList(); } catch (Exception ex) { ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null); } }