private void DbUpdateEvent(string id, DateTime start, DateTime end, string resource) { using (SqlConnection con = new SqlConnection(DbConnect.x)) { int noDay = woringDay.GetNoDay(start, end); con.Open(); SqlCommand cmd = new SqlCommand("uspUpdateLineBooking", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", int.Parse(id)); cmd.Parameters.AddWithValue("@start", start); cmd.Parameters.AddWithValue("@end", end); cmd.Parameters.AddWithValue("@lineNo", resource); cmd.Parameters.AddWithValue("@sumDay", noDay); cmd.ExecuteNonQuery(); } }
protected void GetPo_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(DbConnect.x); try { DataTable dt = new DataTable(); String strQuery = "select DISTINCT po_quantity,Tnapl42,po_xfactory FROM View_Tna_Plan where po_no='" + GetPo.SelectedItem.Text + "' "; SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; cmd.Connection = conn; conn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { //If you want to get mutiple data from the database then you need to write a simple looping txtQuantity.Text = dt.Rows[0]["po_quantity"].ToString(); txtSd.Text = dt.Rows[0]["Tnapl42"].ToString(); txtXd.Text = dt.Rows[0]["po_xfactory"].ToString(); DateTime date1 = new DateTime(); DateTime date2 = new DateTime(); int days; bool isDate1Valid = DateTime.TryParse(txtSd.Text, out date1); bool isDate2Valid = DateTime.TryParse(txtXd.Text, out date2); if (isDate1Valid && isDate2Valid) { ///Friday need to calculate days = wd.GetNoDay(date1, date2); txtSld.Text = (days).ToString(); } } } catch (Exception ex) { throw ex; } finally { conn.Close(); conn.Dispose(); } }
//private void CalculateQty(decimal orderQty, int targetDay, out string remMsg) //{ // //int targetDay = (Convert.ToInt32(txtTargetHr.Text) * Convert.ToInt32(txtPlanHr.Text)); // // decimal remQty = 0, bQty =0; string msg = ""; // // decimal daybook = Math.Ceiling(orderQty / targetDay); // // int noDay = int.Parse(daybook.ToString()); // // int prodQty = targetDay*noDay; // // if (prodQty == orderQty) // // { // // bQty = BookingLine(0, targetDay); // // remQty = orderQty-bQty; // // } // // else if (prodQty > orderQty) // // { // // bQty = BookingLine(int.Parse(noDay.ToString()), targetDay); // // remQty = orderQty - bQty; // // } // // else if (prodQty < orderQty) // // { // // bQty = BookingLine(0, targetDay); // // remQty = orderQty - bQty; // // } // // //if (msg == "") // // //{ // // if (remQty > 900) // // CalculateQty(remQty, prodQty,out remMsg); // //// } // // else // // { // // remMsg = remQty.ToString(); // // } //} private void BookingLine(int orderQty, int targetDay, out int remainQty, int pQtyDay = 0) { int bQTY = 0; int bookDay = 0; int noDay = 0; int bookQty = 0; int midQty = 0; int oQty = orderQty; int[] lc = new int[2]; lc = LCCalculate(orderQty); DataTable dt = (DataTable)ViewState["CurrentTable"]; DataTable lineTab = (DataTable)Session["LineTable"]; DateTime sewingDate = DateTime.Parse(txtSd.Text); DateTime xDate = DateTime.Parse(txtXd.Text); DateTime startDate; DateTime endDate; bool book = false; foreach (DataRow dr in lineTab.Rows) { string line = dr[0].ToString(); // check - is line already booked foreach (DataRow row in dt.Rows) { if (row[2].ToString() == line) { goto nextLine; } } //---------Calculate Learning Curve----------------------------------------------------- bookDay = lc[0]; bookQty = lc[1]; oQty = orderQty - lc[1]; //----------------- ------------------------ -------------------------- DateTime lastDt = DateTime.Parse(dr[2].ToString()); if (lastDt == sewingDate) { startDate = sewingDate.AddDays(1); if (startDate.DayOfWeek == DayOfWeek.Friday) { startDate = startDate.AddDays(1); } } else { startDate = sewingDate; if (startDate.DayOfWeek == DayOfWeek.Friday) { startDate = startDate.AddDays(1); } } if (oQty > targetDay) { decimal daybook = Math.Ceiling(decimal.Parse(oQty.ToString()) / targetDay); noDay = int.Parse(daybook.ToString()); bookDay += noDay; bookQty += oQty; } else if (oQty <= targetDay) { if (oQty > targetDay * .5) { bookDay += 1; bookQty += oQty; } } //else if (oQty <= 0) // BookLine(bookDay, startDate, line); endDate = wd.GetEndDate(startDate, startDate.AddDays(bookDay - 1)); if (lastDt < startDate) //&& (endDate <= xDate)) { //BookLine(startDate, endDate, line); //book = true; //goto lineBookDone; if (endDate <= xDate) { BookLine(startDate, endDate, line); bQTY = bookQty; goto lineBookDone; } else { bookDay = wd.GetNoDay(startDate, xDate); midQty = (bookDay - lc[0]) * targetDay; bookQty = lc[1] + midQty; //bookDay += lc[0]; if (bookDay > 0) { endDate = wd.GetEndDate(startDate, startDate.AddDays(bookDay - 1)); } else { bookDay = lc[0] + 1; endDate = startDate; } BookLine(startDate, endDate, line); bQTY += bookQty; orderQty = orderQty - bookQty; if (orderQty <= targetDay * .5) { goto lineBookDone; } } } //...................... if possible then book the whole order into one line - 1st priority nextLine :; } if (!book) { bQTY = BookMultipleLine(lc, orderQty); } lineBookDone :; remainQty = orderQty - bQTY; int bd = bookDay; //if (bd > 0) // BookLine(bd, remQty, out remQty,pQtyDay,0); }
protected void GetArticle_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(DbConnect.x); try { DataTable dt = new DataTable(); //String strQuery = "select distinct a.po_no,b.gmtyp as art_item,b.gmtid,a.Fact_nm from view_Article_Po a join GarmentsType b on a.art_item = b.gmtid where art_no='" + GetArticle.SelectedItem.Value + "' and a.po_no not in (select Po_no from Line_Booking) "; String strQuery = @"select a.art_no,a.art_item,a.gmtid,a.Fact_nm, sum(po_quantity) as po_quantity, min(Tnapl42) as Tnapl42,min(po_xfactory) as po_xfactory FROM (select distinct a.art_no, b.gmtyp as art_item,b.gmtid,a.Fact_nm from view_Article_Po a join GarmentsType b on a.art_item = b.gmtid where art_no='" + GetArticle.SelectedItem.Text + "') a join View_Tna_Plan v on a.art_no=v.art_no where a.art_no= '" + GetArticle.SelectedItem.Text + "' group by a.art_no, a.art_item,a.gmtid,a.Fact_nm"; SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; cmd.Connection = conn; conn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { GetGType.Text = dt.Rows[0]["art_item"].ToString(); GetFactory.Text = dt.Rows[0]["Fact_nm"].ToString(); Session["GType"] = GetGType.Text; Session["GTypeId"] = dt.Rows[0]["gmtid"]; txtQuantity.Text = dt.Rows[0]["po_quantity"].ToString(); txtSd.Text = dt.Rows[0]["Tnapl42"].ToString(); txtXd.Text = dt.Rows[0]["po_xfactory"].ToString(); DateTime date1 = new DateTime(); DateTime date2 = new DateTime(); int days; bool isDate1Valid = DateTime.TryParse(txtSd.Text, out date1); bool isDate2Valid = DateTime.TryParse(txtXd.Text, out date2); if (isDate1Valid && isDate2Valid) { ///Friday need to calculate days = wd.GetNoDay(date1, date2); txtSld.Text = (days).ToString(); } } ////-----Line grid----- SqlCommand cmd1 = new SqlCommand("select ent_date as StartDate, last_dt as EndDate,line_no, lineQty,line_booking_id as id, target_dy as targetDay,SMV, SumDay from Line_booking where art_no= '" + GetArticle.SelectedItem.Text + "'", conn); cmd1.CommandType = CommandType.Text; DataTable dtt = new DataTable(); da = new SqlDataAdapter(cmd1); da.Fill(dtt); if (dtt.Rows.Count > 0) { ViewState["SMV"] = dtt.Rows[0]["SMV"]; ViewState["TargetDay"] = dtt.Rows[0]["targetDay"]; ViewState["CurrentTable"] = dtt; GridviewHp.DataSource = dtt; GridviewHp.DataBind(); SetPreviousData(); //AddNewRowToGrid(); } GetUsedQty(); } catch (Exception ex) { throw ex; } finally { conn.Close(); conn.Dispose(); } }