using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.Dresses.DressManagement.Rental { public partial class FrmAlsoBack : LYFZ.Software.UI.Dresses.DressManagement.Rental.FrmAlsoBack { LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); LYFZ.BLL.BLL_ErpDressSendWashOrder sworbll = new BLL.BLL_ErpDressSendWashOrder(); LYFZ.BLL.BLL_ErpDressSendWashDetail swodbll = new BLL.BLL_ErpDressSendWashDetail(); LYFZ.BLL.BLL_ErpDressSaleRentalDetail rsdbll = new BLL.BLL_ErpDressSaleRentalDetail(); public FrmAlsoBack() { this.dgv.CellMouseDown += dgv_CellMouseDown; this.dgv.DataGridViewConMenu_ItemClicked += dgv_DataGridViewConMenu_ItemClicked; } /// /// 是否保存 /// public bool IsSaveed = false; /// /// 订单号 /// public string StrOrderNumber; /// /// 订单类型 /// public string OrderType; /// /// 登录者姓名 /// string StrUserName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name; /// /// 窗体加载事件 /// /// /// protected override void FrmAlsoBack_Shown(object sender, EventArgs e) { this.dgv.Rows.Clear(); if (!string.IsNullOrEmpty(this.StrOrderNumber)) { if (this.OrderType == "送洗") { #region 获取礼服资料 DataTable dt = orbll.GetView_Custom("tb_ErpDressSendWashDetail Left Join tb_ErpDressFrom on Dsfm_DressNumber = Dswd_DressNumber", StrWhere: "Dswd_Number='" + this.StrOrderNumber + "'", ShowColumnName: "tb_ErpDressSendWashDetail.ID,Dswd_DressNumber,Dsfm_DressCustomNumber,Dswd_DressName,Dswd_BackStatus,Dswd_BackName,Dswd_BackTime").Tables[0]; for (int t = 0; t < dt.Rows.Count; t++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["ID"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); if (!string.IsNullOrEmpty(dt.Rows[t]["Dsfm_DressCustomNumber"].ToString().Trim())) { cell.Value = dt.Rows[t]["Dsfm_DressCustomNumber"].ToString().Trim(); } else { cell.Value = dt.Rows[t]["Dswd_DressNumber"].ToString().Trim(); } dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Dswd_DressName"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = "1"; dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "1") { cell.Value = "已还"; } else if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "2") { cell.Value = "报损"; } else if (dt.Rows[t]["Dswd_BackStatus"].ToString().Trim() == "3") { cell.Value = "未还"; } dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); DataRow dtRow = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Dswd_BackName"].ToString().Trim()); if (dtRow != null) { cell.Value = dtRow["User_Name"].ToString().Trim(); } else { cell.Value = ""; } dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Dswd_BackTime"]); dgvr.Cells.Add(cell); this.dgv.Rows.Add(dgvr); } this.dgv.ClearSelection(); #endregion } else { #region 获取礼服资料 DataTable dt = orbll.GetView_Custom("tb_ErpDressSaleRentalDetail Left Join tb_ErpDressFrom on Dsfm_DressNumber = Dsrd_DressNumber", StrWhere: "Dsrd_Number='" + this.StrOrderNumber + "'", ShowColumnName: "tb_ErpDressSaleRentalDetail.ID,Dsrd_DressNumber,Dsfm_DressCustomNumber,Dsrd_DressName,Dsrd_BackStatus,Dsrd_BackName,Dsrd_BackTime").Tables[0]; for (int t = 0; t < dt.Rows.Count; t++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["ID"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Dsrd_DressNumber"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["Dsrd_DressName"].ToString().Trim(); dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = "1"; dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "1") { cell.Value = "已还"; } else if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "2") { cell.Value = "报损"; } else if (dt.Rows[t]["Dsrd_BackStatus"].ToString().Trim() == "3") { cell.Value = "未还"; } dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); DataRow dtRow = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[t]["Dsrd_BackName"].ToString().Trim()); if (dtRow != null) { cell.Value = dtRow["User_Name"].ToString().Trim(); } else { cell.Value = ""; } dgvr.Cells.Add(cell); cell = new DataGridViewTextBoxCell(); cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["Dsrd_BackTime"]); dgvr.Cells.Add(cell); this.dgv.Rows.Add(dgvr); } this.dgv.ClearSelection(); #endregion } } } /// /// dgv控件里面塞下拉框 /// /// /// protected override void cmbFactory_Leave(object sender, EventArgs e) { this.dgv.CurrentRow.Cells["Dsrd_BackStatus"].Value = this.cmbFactory.Text.Trim(); if (this.dgv.CurrentRow.Cells["Dsrd_BackStatus"].Value.ToString().Trim() == "未还") { this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = ""; this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = ""; } else { this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = this.StrUserName; this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = LYFZ.Command.Command_Validate.DateTimeToString(SDateTime.Now); } this.dgv.CurrentRow.Tag = "1"; this.cmbFactory.Visible = false; } /// /// 双击列表事件 /// /// /// protected override void dgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (this.dgv.Rows.Count > 0) { if (e.RowIndex >= 0) { if (this.dgv.CurrentCell.ColumnIndex == this.dgv.Columns["Dsrd_BackStatus"].Index) { DataGridViewCell cell = this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]; Rectangle rect = this.dgv.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true); this.cmbFactory.Location = new Point(rect.Location.X + this.dgv.Location.X, rect.Location.Y + this.dgv.Location.Y); this.cmbFactory.Size = rect.Size; if (cell.Value != null) { this.cmbFactory.Text = (string)cell.Value; } this.cmbFactory.Visible = true; this.cmbFactory.Focus(); } } } } /// /// 关闭 /// /// /// protected override void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 保存 /// /// /// protected override void btnSave_Click(object sender, EventArgs e) { if (this.dgv.Rows.Count > 0) { DateTime StrTime = SDateTime.Now; string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; List clist = new List(); int YHCount = 0; for (int i = 0; i < this.dgv.Rows.Count; i++) { if (this.dgv.Rows[i].Tag != null) { string StrBackStatus = ""; switch (this.dgv.Rows[i].Cells["Dsrd_BackStatus"].Value.ToString().Trim()) { case "已还": StrBackStatus = "1"; YHCount++; break; case "报损": StrBackStatus = "2"; break; case "未还": StrBackStatus = "3"; break; } if (this.OrderType == "送洗") { LYFZ.Model.Model_ErpDressSendWashDetail model = swodbll.GetModel(Convert.ToInt32(this.dgv.Rows[i].Cells["ID"].Value)); model.Dswd_BackStatus = StrBackStatus; if (StrBackStatus == "3") { model.Dswd_BackTime = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime(); model.Dswd_BackName = ""; } else { model.Dswd_BackTime = StrTime; model.Dswd_BackName = StrUserID; } model.Dswd_UpdateDatetime = StrTime; model.Dswd_UpdateName = StrUserID; clist.Add(swodbll.GetUpdateCommandInfo(model)); } else { LYFZ.Model.Model_ErpDressSaleRentalDetail model = rsdbll.GetModel(Convert.ToInt32(this.dgv.Rows[i].Cells["ID"].Value)); model.Dsrd_BackStatus = StrBackStatus; if (StrBackStatus == "3") { model.Dsrd_BackTime = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime(); model.Dsrd_BackName = ""; } else { model.Dsrd_BackTime = StrTime; model.Dsrd_BackName = StrUserID; } model.Dsrd_UpdateDateTime = StrTime; model.Dsrd_UpdateName = StrUserID; clist.Add(rsdbll.GetUpdateCommandInfo(model)); } } } if (clist.Count > 0) { if (MessageBoxCustom.Show("你确定要保存吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0) { this.IsSaveed = true; System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { if (this.OrderType != "送洗" && this.dgv.Rows.Count==YHCount) { Model.SMSParameters sparameters = new Model.SMSParameters(); sparameters.OrderNumber = this.StrOrderNumber; new LYFZ.BLL.BLL_SMSTemplates().GenerateEventSMS(EnumPublic.SmsSendEvent.礼服出租还衣后X分钟, sparameters, MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID); } })); t.Start(); MessageBoxCustom.Show("保存成功!"); } else { MessageBoxCustom.Show("保存失败!"); } } else { MessageBoxCustom.Show("没做任何修改,不需要保存!"); } } } /// /// 右键菜单 /// /// /// void dgv_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { this.cmbFactory.Visible = false; if (e.Button == MouseButtons.Right) { ToolStripMenuItem item = null; if (e.ColumnIndex == this.dgv.Columns["Dsrd_BackStatus"].Index) { if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.StoresTotakePiece, LYFZ.CustomAttributes.OperatingAuthority.OrderSendOut)) { item = new ToolStripMenuItem(); item.Text = "已还"; item.Tag = "S"; this.dgv.conMenu.Items.Add(item); item = new ToolStripMenuItem(); item.Text = "未还"; item.Tag = "S"; this.dgv.conMenu.Items.Add(item); } } } } /// /// 右键菜单选择项事件 /// /// /// void dgv_DataGridViewConMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripItem item = e.ClickedItem; if (item.Tag.ToString().Trim() == "S" && !string.IsNullOrEmpty(item.Text.Trim())) { for (int i = 0; i < this.dgv.SelectedRows.Count; i++) { this.dgv.SelectedRows[i].Cells["Dsrd_BackStatus"].Value = item.Text.Trim(); if (item.Text.Trim() == "未还") { this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = ""; this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = ""; } else { this.dgv.CurrentRow.Cells["Dsro_UpdateName"].Value = this.StrUserName; this.dgv.CurrentRow.Cells["Dsrd_BackTime"].Value = LYFZ.Command.Command_Validate.DateTimeToString(SDateTime.Now); } this.dgv.SelectedRows[i].Tag = "1"; } } } } }