// private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (this.dataGridView1.Rows[e.RowIndex].Cells["ID"].Value == null) { return; } int id = (int)this.dataGridView1.Rows[e.RowIndex].Cells["ID"].Value; //openMode == 0用于选择 if (openMode == 0) { Card card = CardDao.getInstance().FindByID(id); LookupArg lookupArg = new LookupArg(id, card.getInfo(card.LeftNumber)); //借用这个传剩下数量 lookupArg.ArgName = card.LeftNumber.ToString(); this.Close(); this.invokeLookupCallback(lookupArg); } else if (openMode == 1) { /*if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count <= 0) * { * MessageBox.Show("请选择卡片!"); * return; * }*/ editCard(this.dataGridView1.SelectedRows[0]); } }
//del private void toolStripButton2_Click(object sender, EventArgs e) { List <int> list = this.dataGridView1.getSelectIDs("ID", "check"); if (list == null || list.Count <= 0) { MessageBox.Show("请选择单据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } StringBuilder ids = new StringBuilder(); for (int ii = 0; ii < list.Count; ii++) { ids.Append(list[ii]); ids.Append(" "); } if (MessageBox.Show(string.Format("是否删除流水号为{0}的卡片?", ids.ToString()), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { for (int i = 0; i < list.Count; i++) { if (CardDao.getInstance().FindByID(list[i]).Status > 1) { MessageBox.Show(string.Format("ID为{0}的卡片已经审核, 无法删除!", list[i]), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); initList(); return; } CardDao.getInstance().Delete(list[i]); } initList(); MessageBox.Show("删除单据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//审核 private void toolStripButton_finish_Click(object sender, EventArgs e) { string tips = "是否审核?"; if (MessageBox.Show(tips, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } if (this.getCard(out card) == false) { return; } //2018-4-20修复的bug if (CardDao.getInstance().FindByID(card.ID) == null) { MessageBox.Show("该卡片已经被删除了。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } card.CardTime = DateTime.Now; card.Status = 3; CardDao.getInstance().Update(card); this.initCard(); MessageBox.Show("审核成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.invokeUpdateNotify(UpdateType.CardUpdate); }
private void initList() { try { CardDao cardDao = CardDao.getInstance(); DateTime startTime = this.dateTimePicker3.Value; DateTime endTime = this.dateTimePicker4.Value.AddDays(1); int statusQuery = 3; if (openMode == 1) { statusQuery = (int)(comboBox1.SelectedValue); } DataTable dataTable = cardDao.FindList(startTime, endTime, statusQuery, textBox_customer.Text.Trim()); this.dataGridView1.Rows.Clear(); int index = 0; foreach (DataRow dr in dataTable.Rows) { index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells["ID"].Value = dr["ID"]; this.dataGridView1.Rows[index].Cells["name"].Value = dr["code"]; this.dataGridView1.Rows[index].Cells["customer"].Value = dr["name"]; /*int type = (int)(dr["type"]); * this.dataGridView1.Rows[index].Cells["type"].Value = ProductCirculation.CirculationTypeConfs[type - 1].name; * this.dataGridView1.Rows[index].Cells["typeValue"].Value = type;*/ double realTotal = double.Parse(dr["total"].ToString()); this.dataGridView1.Rows[index].Cells["realTotal"].Value = realTotal.ToString("0.00"); this.dataGridView1.Rows[index].Cells["num"].Value = dr["num"]; this.dataGridView1.Rows[index].Cells["leftNum"].Value = dr["leftNum"]; int status = (int)(dr["status"]); this.dataGridView1.Rows[index].Cells["status"].Value = Card.cardStatusContext[status - 1]; if (status == 1) { this.dataGridView1.Rows[index].Cells["status"].Style.ForeColor = Color.Red; this.dataGridView1.Rows[index].Cells["status"].Style.SelectionForeColor = Color.Red; } else { this.dataGridView1.Rows[index].Cells["status"].Style.ForeColor = Color.Black; this.dataGridView1.Rows[index].Cells["status"].Style.SelectionForeColor = Color.Black; } this.dataGridView1.Rows[index].Cells["sellTime"].Value = ((DateTime)dr["cardTime"]).ToString("yyyy-MM-dd HH:mm:ss"); } } catch (Exception ex) { MessageBox.Show("查询错误, 请输入正确的条件.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { this.firstLoad = false; } }
//对内提供服务的函数,调用switch mode,其实可以把openMode作为参数 private void initCard() { //2020-1-18 这里只分两种情况,除了0之外,其他情况还要根据card的status来重设openMode if (openMode == 0) { int max = 1;// CirDao.getMaxCode(string.Format("CARD-{0}-", DateTime.Now.ToString("yyyyMMdd"))); this.textBox_serial.Text = string.Format("CARD-{0}-{1:0000}", DateTime.Now.ToString("yyyyMMdd"), max + 1); this.dateTime_cardTime.Value = DateTime.Now; this.textBox_num.Text = ""; this.textBox_realTotal.Text = ""; this.textBox_comment.Text = null; this.textBox_operator.Text = ConfDao.getInstance().Get(5).ToString(); this.lookupText1.LookupArg = null; this.lookupText1.Text_Lookup = null; } else { card = CardDao.getInstance().FindByID(cardID); this.textBox_serial.Text = card.Code; this.dateTime_cardTime.Value = card.CardTime; this.textBox_realTotal.Text = card.Total.ToString(); this.textBox_num.Text = card.Number.ToString(); this.textBox_leftNum.Text = card.LeftNumber.ToString(); this.textBox_comment.Text = card.Comment; this.textBox_operator.Text = card.Oper; this.lookupText1.LookupArg = new LookupArg(card.CustomerID, card.CustomerName); this.lookupText1.Text_Lookup = card.CustomerName; List <Consume> list = ConsumeDao.getInstance().FindList(cardID, 4); this.dataGridView1.Rows.Clear(); for (int i = 0; i < list.Count; i++) { Consume consume = list[i]; this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[i].Cells["ID"].Value = consume.ID; this.dataGridView1.Rows[i].Cells["name"].Value = consume.Code; this.dataGridView1.Rows[i].Cells["num"].Value = consume.Number; int status = consume.Status; this.dataGridView1.Rows[i].Cells["status"].Value = Consume.consumeStatusContext[status - 1]; this.dataGridView1.Rows[i].Cells["sellTime"].Value = consume.ConsumeTime.ToString("yyyy-MM-dd HH:mm:ss"); } openMode = card.Status; } switchMode(openMode); resetNeedSave(false); }
//审核 private void toolStripButton_finish_Click(object sender, EventArgs e) { string tips = "审核后将从卡里扣除次数,是否继续?"; if (MessageBox.Show(tips, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } this.getConsume(out consume); consume = ConsumeDao.getInstance().FindByID(consumeID); //2018-4-20修复的bug if (consume == null) { MessageBox.Show("该消费已经被删除了。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Card card = consume.Card; if (consume.Number > card.LeftNumber) { MessageBox.Show("该消费次数超过剩余次数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } consume.ConsumeTime = DateTime.Now; consume.LeftNumber = card.LeftNumber; consume.Status = 4; ConsumeDao.getInstance().Update(consume); card.LeftNumber = card.LeftNumber - consume.Number; if (card.LeftNumber == 0) { card.Status = 4; } CardDao.getInstance().Update(card); MessageBox.Show("审核成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.initConsume(); this.invokeUpdateNotify(UpdateType.ConsumeUpdate); this.invokeUpdateNotify(UpdateType.CardUpdate); }
/// <summary> /// for event /// </summary> /// protected void toolStripButton_save_Click(object sender, EventArgs e) { bool isSellCorrect = getCard(out card); if (isSellCorrect == false) { return; } card.Status = 1; // if (this.openMode == 1 && CardDao.getInstance().FindByID(card.ID) == null) { MessageBox.Show("该单据已经被删除了。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.Enabled = true; return; } try { if (openMode == 0) { CardDao.getInstance().Insert(card, out cardID); MessageBox.Show(string.Format("增加{0}成功!", this.Text), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); openMode = 1; } else if (openMode == 1) { CardDao.getInstance().Update(card); MessageBox.Show(string.Format("保存{0}成功!", this.Text), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } //主要是保存按钮恢复到初始状态 this.initCard(); } catch (Exception ex) { MessageBox.Show("保存有误,可能是往来单位或货品属性被修改过,请重新编辑!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } //so important: if edit ,it should be refresh also, because edit will del exist item and add new item this.invokeUpdateNotify(UpdateType.CardUpdate); }
//弃核 private void toolStripButton_finishCancel_Click(object sender, EventArgs e) { if (MessageBox.Show("是否弃核,退回到未审核状态?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } if (ConsumeDao.getInstance().FindList(cardID, 0).Count > 0) { MessageBox.Show("弃核失败,该卡片已经消费过,请先删除相应的消费。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } card.Status = 1; card.CardTime = DateTime.Now; CardDao.getInstance().Update(card); MessageBox.Show("弃核成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.initCard(); this.invokeUpdateNotify(UpdateType.CardUpdate); }
//弃核 private void toolStripButton_finishCancel_Click(object sender, EventArgs e) { if (MessageBox.Show("是否弃核,退回到未审核状态?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } List <Consume> cons = ConsumeDao.getInstance().FindList(consume.CardID, 0); if (cons[cons.Count - 1].ID > consume.ID) { MessageBox.Show("弃核失败,该卡片后面还有消费,请先删除相应的消费。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } consume.Status = 1; consume.ConsumeTime = DateTime.Now; ConsumeDao.getInstance().Update(consume); //注意这里,这样合不合理,如果通过dao find出来就没问题,如果是this.getConsume就不行,getConsume后,还是重新find一下,这样就没问题 Card card = consume.Card; if (card.LeftNumber == 0) { card.Status = 3; } card.LeftNumber += consume.Number; CardDao.getInstance().Update(card); MessageBox.Show("弃核成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.initConsume(); this.invokeUpdateNotify(UpdateType.CardUpdate); this.invokeUpdateNotify(UpdateType.ConsumeUpdate); }