protected override void initList()
        {
            DataTable dataTable = ProductStainlessCirculationRecordDao.getInstance().FindList(
                this.dateTimePicker3.Value, this.dateTimePicker4.Value.AddDays(1), 0,
                this.textBox_product.Text, -1, this.textBox_customer.Text, -1);

            this.dataGridView1.Rows.Clear();
            foreach (DataRow dr in dataTable.Rows)
            {
                int index = this.dataGridView1.Rows.Add();

                this.dataGridView1.Rows[index].Cells["serial"].Value = dr["serial"];
                this.dataGridView1.Rows[index].Cells["name"].Value   = dr["ProductStainless.name"];

                int type = (int)(dr["type"]);
                this.dataGridView1.Rows[index].Cells["type"].Value = ProductCirculation.CirculationTypeConfs[type - 1].name;

                this.dataGridView1.Rows[index].Cells["time"].Value = dr["circulationTime"];

                double num;
                double.TryParse(dr["totalNum"].ToString(), out num);// *(int)dr["flowType"];
                if (type == 1 || type == 4 || type == 5 || type == 8)
                {
                    ControlUtility.setCellWithColor(dataGridView1.Rows[index].Cells["num"], Color.Red, string.Format("+{0}", num));
                }
                else if (type == 2 || type == 3 || type == 6 || type == 7)
                {
                    ControlUtility.setCellWithColor(dataGridView1.Rows[index].Cells["num"], Color.Green, string.Format("-{0}", num));
                }

                this.dataGridView1.Rows[index].Cells["unit"].Value = dr["unit"];

                this.dataGridView1.Rows[index].Cells["customer"].Value = dr["circulation.name"];
            }
        }
        //for event: caculate total price
        protected override void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType().Equals(typeof(DataGridViewTextBoxEditingControl)))//cell为类TextBox时
            {
                e.CellStyle.BackColor = Color.FromName("window");
                DataGridViewTextBoxEditingControl editingControl = e.Control as DataGridViewTextBoxEditingControl;

                editingControl.TextChanged -= new EventHandler(editingControl_TextChanged);
                editingControl.TextChanged += new EventHandler(editingControl_TextChanged);
            }
            else if (e.Control.GetType().Equals(typeof(DataGridViewComboBoxEditEditingControl)))//cell为price时
            {
                e.CellStyle.BackColor = Color.FromName("window");

                DataGridViewComboBoxEditEditingControl editingControl = e.Control as DataGridViewComboBoxEditEditingControl;
                editingControl.Items.Clear();
                int productID = 0, customerID = 0;

                DataGridViewLookupCell cell = editingControl.EditingControlDataGridView.Rows[editingControl.EditingControlRowIndex].Cells["product"] as DataGridViewLookupCell;
                if (cell.Value != null && !string.IsNullOrEmpty((cell.Value as LookupArg).ArgName))
                {
                    productID = (int)(cell.Value as LookupArg).Value;
                }
                if (this.lookupText1.LookupArg != null)
                {
                    int.TryParse(this.lookupText1.LookupArg.Value.ToString(), out customerID);
                }

                if (productID != 0 && customerID != 0)
                {
                    List <string> prices = ProductStainlessCirculationRecordDao.getInstance().FindPriceList((int)conf.type, productID, customerID);
                    //items是放在column里
                    editingControl.Items.AddRange(prices.ToArray());
                }

                editingControl.TextChanged -= new EventHandler(editingControl_TextChanged);
                editingControl.TextChanged += new EventHandler(editingControl_TextChanged);
            }
            else if (e.Control.GetType().Equals(typeof(DataGridViewLookupEditingControl)))
            {
                DataGridViewLookupEditingControl editingControl = e.Control as DataGridViewLookupEditingControl;
                string columnName = this.dataGridView1.CurrentCell.OwningColumn.Name;
                editingControl.valueSetted -= new LookupText.ValueSetted(productEditingControl_valueSetted);
                editingControl.valueSetted += new LookupText.ValueSetted(productEditingControl_valueSetted);
            }
        }
예제 #3
0
        protected override void getSum(DateTime start, DateTime end, int type, int productID, int customerID, out double totalNum, out double sum)
        {
            DataTable dt = ProductStainlessCirculationRecordDao.getInstance().FindList(start, end.AddDays(1).AddSeconds(-1), type, null, productID, null, customerID);

            totalNum = 0;
            sum      = 0;
            foreach (DataRow row in dt.Rows)
            {
                double tempNum;
                double.TryParse(row["totalNum"].ToString(), out tempNum);

                double tempDouble = 0;
                double.TryParse(row["price"].ToString(), out tempDouble);
                int flowType = (int)row["flowType"];

                totalNum += tempNum * flowType;
                sum      += tempDouble * tempNum * flowType;
            }

            sum      = Math.Abs(sum);
            totalNum = Math.Abs(totalNum);
        }